diff --git a/index.html b/index.html index fc41870..15ccd93 100644 --- a/index.html +++ b/index.html @@ -13,6 +13,7 @@ + diff --git a/js/engine/EncryptNormalMorse.js b/js/engine/EncryptNormalMorse.js new file mode 100644 index 0000000..df37ffc --- /dev/null +++ b/js/engine/EncryptNormalMorse.js @@ -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 + "       " + input = input.substring(1, input.length) + } else if (input.startsWith("A")) { + output = output + ".-   " + input = input.substring(1, input.length) + } else if (input.startsWith("B")) { + output = output +"-...   " + input = input.substring(1, input.length) + } else if (input.startsWith("C")) { + output = output +"-.-.   " + input = input.substring(1, input.length) + } else if (input.startsWith("D")) { + output = output +"-..   " + input = input.substring(1, input.length) + } else if (input.startsWith("E")) { + output = output +".   " + input = input.substring(1, input.length) + } else if (input.startsWith("F")) { + output = output +"..-.   " + input = input.substring(1, input.length) + } else if (input.startsWith("G")) { + output = output +"--.   " + input = input.substring(1, input.length) + } else if (input.startsWith("H")) { + output = output +"....   " + input = input.substring(1, input.length) + } else if (input.startsWith("I")) { + output = output +"..   " + input = input.substring(1, input.length) + } else if (input.startsWith("J")) { + output = output +".---   " + input = input.substring(1, input.length) + } else if (input.startsWith("K")) { + output = output +"-.-   " + input = input.substring(1, input.length) + } else if (input.startsWith("L")) { + output = output +".-..   " + input = input.substring(1, input.length) + } else if (input.startsWith("M")) { + output = output +"--   " + input = input.substring(1, input.length) + } else if (input.startsWith("N")) { + output = output +"-.   " + input = input.substring(1, input.length) + } else if (input.startsWith("O")) { + output = output +"---   " + input = input.substring(1, input.length) + } else if (input.startsWith("P")) { + output = output +".--.   " + input = input.substring(1, input.length) + } else if (input.startsWith("Q")) { + output = output +"--.-   " + input = input.substring(1, input.length) + } else if (input.startsWith("R")) { + output = output +".-.   " + input = input.substring(1, input.length) + } else if (input.startsWith("S")) { + output = output +"...   " + input = input.substring(1, input.length) + } else if (input.startsWith("T")) { + output = output +"-   " + input = input.substring(1, input.length) + } else if (input.startsWith("U")) { + output = output +"..-   " + input = input.substring(1, input.length) + } else if (input.startsWith("V")) { + output = output +"...-   " + input = input.substring(1, input.length) + } else if (input.startsWith("W")) { + output = output +".--   " + input = input.substring(1, input.length) + } else if (input.startsWith("X")) { + output = output +"-..-   " + input = input.substring(1, input.length) + } else if (input.startsWith("Y")) { + output = output +"-.--   " + input = input.substring(1, input.length) + } else if (input.startsWith("Z")) { + output = output +"--..   " + input = input.substring(1, input.length) + } else if (input.startsWith("0")) { + output = output +"-----   " + input = input.substring(1, input.length) + } else if (input.startsWith("1")) { + output = output +".----   " + input = input.substring(1, input.length) + } else if (input.startsWith("2")) { + output = output +"..---   " + input = input.substring(1, input.length) + } else if (input.startsWith("3")) { + output = output +"...--   " + input = input.substring(1, input.length) + } else if (input.startsWith("4")) { + output = output +"....-   " + input = input.substring(1, input.length) + } else if (input.startsWith("5")) { + output = output +".....   " + input = input.substring(1, input.length) + } else if (input.startsWith("6")) { + output = output +"-....   " + input = input.substring(1, input.length) + } else if (input.startsWith("7")) { + output = output +"--...   " + input = input.substring(1, input.length) + } else if (input.startsWith("8")) { + output = output +"---..   " + input = input.substring(1, input.length) + } else if (input.startsWith("9")) { + output = output +"----.   " + input = input.substring(1, input.length) + } else if (input.startsWith("Ä")) { + output = output +".-.-   " + input = input.substring(1, input.length) + } else if (input.startsWith("Ö")) { + output = output +"---.   " + input = input.substring(1, input.length) + } else if (input.startsWith("Ü")) { + output = output +"..--   " + input = input.substring(1, input.length) + } else if (input.startsWith("ß")) { + output = output +"...--...   " + input = input.substring(1, input.length) + } else if (input.startsWith(".")) { + output = output +".-.-.-   " + input = input.substring(1, input.length) + } else if (input.startsWith(",")) { + output = output +"--..--   " + input = input.substring(1, input.length) + } else if (input.startsWith(":")) { + output = output +"---...   " + input = input.substring(1, input.length) + } else if (input.startsWith(";")) { + output = output +"-.-.-.   " + input = input.substring(1, input.length) + } else if (input.startsWith("?")) { + output = output +"..--..   " + input = input.substring(1, input.length) + } else if (input.startsWith("!")) { + output = output +"-.-.--   " + input = input.substring(1, input.length) + } else if (input.startsWith("-")) { + output = output +"-....-   " + input = input.substring(1, input.length) + } else if (input.startsWith("_")) { + output = output +"..--.-   " + input = input.substring(1, input.length) + } else if (input.startsWith("(")) { + output = output +"-.--.   " + input = input.substring(1, input.length) + } else if (input.startsWith(")")) { + output = output +"-.--.-   " + input = input.substring(1, input.length) + } else if (input.startsWith("=")) { + output = output +"-...-   " + input = input.substring(1, input.length) + } else if (input.startsWith("+")) { + output = output +".-.-.   " + input = input.substring(1, input.length) + } else if (input.startsWith("/")) { + output = output +"-..-.   " + input = input.substring(1, input.length) + } else if (input.startsWith("@")) { + output = output +".--.-.   " + input = input.substring(1, input.length) + } else if (input.startsWith("'")) { + output = output +".----.   " + input = input.substring(1, input.length) + } else if (input.startsWith("$")) { + output = output +"...-..-   " + input = input.substring(1, input.length) + } else { + output = "Code not listed or wrong." + } + } + if (output.endsWith("   ")) { + output = output.substring(0, output.length - 18) + } + } + return output + } +} diff --git a/js/web/web.js b/js/web/web.js index 3fe87cf..40e4079 100644 --- a/js/web/web.js +++ b/js/web/web.js @@ -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) }