Added the normal morse encryption

This commit is contained in:
mmk2410 2015-04-16 23:48:18 +02:00
parent 0e78a407e5
commit 954f57f221
3 changed files with 222 additions and 1 deletions

View file

@ -13,6 +13,7 @@
<script src="js/web/web.js"></script>
<script src="js/engine/EncryptWrittenMorse.js"></script>
<script src="js/engine/DecryptWrittenMorse.js"></script>
<script src="js/engine/EncryptNormalMorse.js"></script>
<script src="js/engine/DecryptNormalMorse.js"></script>
</head>

View file

@ -0,0 +1,220 @@
function encryptNormalMorseManager(message) {
if(message == ""){
return "Please enter at least one character"
} else {
if (message.endsWith(" ")) {
message = message.substring(0, message.length - 3)
}
// Variables
var input = message.toUpperCase()
while(input.indexOf('\n') != -1){
input = input.replace("\n","")
}
var output = ""
if (input == "LETTERSPACE") {
output = " "
} else if (input == "END OF WORK") {
output = "...-.-"
} else if (input == "ERROR") {
output = "........"
} else if (input == "STARTING SIGNAL") {
output = "-.-.-"
} else if (input == "ENDING SIGNAL") {
output = ".-.-."
} else if (input == "UNDERSTOOD") {
output = "...-."
} else if (input == "WAIT") {
output = ".-..."
} else if (input == "SOS") {
output = "...---..."
} else if (input == "LETTER SPACE") {
output = " "
} else if (input == "WORD SPACE") {
output = " "
} else {
for (var c = input.length; c > 0; c--) {
if (input.startsWith(" ")) {
if (output.endsWith(" ")) {
output = output.substring(0, output.length - 3)
}
output = output + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
input = input.substring(1, input.length)
} else if (input.startsWith("A")) {
output = output + ".-&nbsp;&nbsp;&nbsp;"
input = input.substring(1, input.length)
} else if (input.startsWith("B")) {
output = output +"-...&nbsp;&nbsp;&nbsp;"
input = input.substring(1, input.length)
} else if (input.startsWith("C")) {
output = output +"-.-.&nbsp;&nbsp;&nbsp;"
input = input.substring(1, input.length)
} else if (input.startsWith("D")) {
output = output +"-..&nbsp;&nbsp;&nbsp;"
input = input.substring(1, input.length)
} else if (input.startsWith("E")) {
output = output +".&nbsp;&nbsp;&nbsp;"
input = input.substring(1, input.length)
} else if (input.startsWith("F")) {
output = output +"..-.&nbsp;&nbsp;&nbsp;"
input = input.substring(1, input.length)
} else if (input.startsWith("G")) {
output = output +"--.&nbsp;&nbsp;&nbsp;"
input = input.substring(1, input.length)
} else if (input.startsWith("H")) {
output = output +"....&nbsp;&nbsp;&nbsp;"
input = input.substring(1, input.length)
} else if (input.startsWith("I")) {
output = output +"..&nbsp;&nbsp;&nbsp;"
input = input.substring(1, input.length)
} else if (input.startsWith("J")) {
output = output +".---&nbsp;&nbsp;&nbsp;"
input = input.substring(1, input.length)
} else if (input.startsWith("K")) {
output = output +"-.-&nbsp;&nbsp;&nbsp;"
input = input.substring(1, input.length)
} else if (input.startsWith("L")) {
output = output +".-..&nbsp;&nbsp;&nbsp;"
input = input.substring(1, input.length)
} else if (input.startsWith("M")) {
output = output +"--&nbsp;&nbsp;&nbsp;"
input = input.substring(1, input.length)
} else if (input.startsWith("N")) {
output = output +"-.&nbsp;&nbsp;&nbsp;"
input = input.substring(1, input.length)
} else if (input.startsWith("O")) {
output = output +"---&nbsp;&nbsp;&nbsp;"
input = input.substring(1, input.length)
} else if (input.startsWith("P")) {
output = output +".--.&nbsp;&nbsp;&nbsp;"
input = input.substring(1, input.length)
} else if (input.startsWith("Q")) {
output = output +"--.-&nbsp;&nbsp;&nbsp;"
input = input.substring(1, input.length)
} else if (input.startsWith("R")) {
output = output +".-.&nbsp;&nbsp;&nbsp;"
input = input.substring(1, input.length)
} else if (input.startsWith("S")) {
output = output +"...&nbsp;&nbsp;&nbsp;"
input = input.substring(1, input.length)
} else if (input.startsWith("T")) {
output = output +"-&nbsp;&nbsp;&nbsp;"
input = input.substring(1, input.length)
} else if (input.startsWith("U")) {
output = output +"..-&nbsp;&nbsp;&nbsp;"
input = input.substring(1, input.length)
} else if (input.startsWith("V")) {
output = output +"...-&nbsp;&nbsp;&nbsp;"
input = input.substring(1, input.length)
} else if (input.startsWith("W")) {
output = output +".--&nbsp;&nbsp;&nbsp;"
input = input.substring(1, input.length)
} else if (input.startsWith("X")) {
output = output +"-..-&nbsp;&nbsp;&nbsp;"
input = input.substring(1, input.length)
} else if (input.startsWith("Y")) {
output = output +"-.--&nbsp;&nbsp;&nbsp;"
input = input.substring(1, input.length)
} else if (input.startsWith("Z")) {
output = output +"--..&nbsp;&nbsp;&nbsp;"
input = input.substring(1, input.length)
} else if (input.startsWith("0")) {
output = output +"-----&nbsp;&nbsp;&nbsp;"
input = input.substring(1, input.length)
} else if (input.startsWith("1")) {
output = output +".----&nbsp;&nbsp;&nbsp;"
input = input.substring(1, input.length)
} else if (input.startsWith("2")) {
output = output +"..---&nbsp;&nbsp;&nbsp;"
input = input.substring(1, input.length)
} else if (input.startsWith("3")) {
output = output +"...--&nbsp;&nbsp;&nbsp;"
input = input.substring(1, input.length)
} else if (input.startsWith("4")) {
output = output +"....-&nbsp;&nbsp;&nbsp;"
input = input.substring(1, input.length)
} else if (input.startsWith("5")) {
output = output +".....&nbsp;&nbsp;&nbsp;"
input = input.substring(1, input.length)
} else if (input.startsWith("6")) {
output = output +"-....&nbsp;&nbsp;&nbsp;"
input = input.substring(1, input.length)
} else if (input.startsWith("7")) {
output = output +"--...&nbsp;&nbsp;&nbsp;"
input = input.substring(1, input.length)
} else if (input.startsWith("8")) {
output = output +"---..&nbsp;&nbsp;&nbsp;"
input = input.substring(1, input.length)
} else if (input.startsWith("9")) {
output = output +"----.&nbsp;&nbsp;&nbsp;"
input = input.substring(1, input.length)
} else if (input.startsWith("Ä")) {
output = output +".-.-&nbsp;&nbsp;&nbsp;"
input = input.substring(1, input.length)
} else if (input.startsWith("Ö")) {
output = output +"---.&nbsp;&nbsp;&nbsp;"
input = input.substring(1, input.length)
} else if (input.startsWith("Ü")) {
output = output +"..--&nbsp;&nbsp;&nbsp;"
input = input.substring(1, input.length)
} else if (input.startsWith("ß")) {
output = output +"...--...&nbsp;&nbsp;&nbsp;"
input = input.substring(1, input.length)
} else if (input.startsWith(".")) {
output = output +".-.-.-&nbsp;&nbsp;&nbsp;"
input = input.substring(1, input.length)
} else if (input.startsWith(",")) {
output = output +"--..--&nbsp;&nbsp;&nbsp;"
input = input.substring(1, input.length)
} else if (input.startsWith(":")) {
output = output +"---...&nbsp;&nbsp;&nbsp;"
input = input.substring(1, input.length)
} else if (input.startsWith(";")) {
output = output +"-.-.-.&nbsp;&nbsp;&nbsp;"
input = input.substring(1, input.length)
} else if (input.startsWith("?")) {
output = output +"..--..&nbsp;&nbsp;&nbsp;"
input = input.substring(1, input.length)
} else if (input.startsWith("!")) {
output = output +"-.-.--&nbsp;&nbsp;&nbsp;"
input = input.substring(1, input.length)
} else if (input.startsWith("-")) {
output = output +"-....-&nbsp;&nbsp;&nbsp;"
input = input.substring(1, input.length)
} else if (input.startsWith("_")) {
output = output +"..--.-&nbsp;&nbsp;&nbsp;"
input = input.substring(1, input.length)
} else if (input.startsWith("(")) {
output = output +"-.--.&nbsp;&nbsp;&nbsp;"
input = input.substring(1, input.length)
} else if (input.startsWith(")")) {
output = output +"-.--.-&nbsp;&nbsp;&nbsp;"
input = input.substring(1, input.length)
} else if (input.startsWith("=")) {
output = output +"-...-&nbsp;&nbsp;&nbsp;"
input = input.substring(1, input.length)
} else if (input.startsWith("+")) {
output = output +".-.-.&nbsp;&nbsp;&nbsp;"
input = input.substring(1, input.length)
} else if (input.startsWith("/")) {
output = output +"-..-.&nbsp;&nbsp;&nbsp;"
input = input.substring(1, input.length)
} else if (input.startsWith("@")) {
output = output +".--.-.&nbsp;&nbsp;&nbsp;"
input = input.substring(1, input.length)
} else if (input.startsWith("'")) {
output = output +".----.&nbsp;&nbsp;&nbsp;"
input = input.substring(1, input.length)
} else if (input.startsWith("$")) {
output = output +"...-..-&nbsp;&nbsp;&nbsp;"
input = input.substring(1, input.length)
} else {
output = "Code not listed or wrong."
}
}
if (output.endsWith("&nbsp;&nbsp;&nbsp;")) {
output = output.substring(0, output.length - 18)
}
}
return output
}
}

View file

@ -24,7 +24,7 @@ function encrypt(){
$("#output").text(encryptWrittenMorseManager(input))
} else {
//TODO port the normal morse decode engine
$("#output").text("The normal morse engine is not ported jet.")
$("#output").html(encryptNormalMorseManager(input))
}
$('#outputcard').fadeIn(dur)
}