diff --git a/index.html b/index.html index e86df0a..fc41870 100644 --- a/index.html +++ b/index.html @@ -13,6 +13,7 @@ + diff --git a/js/engine/DecryptNormalMorse.js b/js/engine/DecryptNormalMorse.js new file mode 100644 index 0000000..3d91d2c --- /dev/null +++ b/js/engine/DecryptNormalMorse.js @@ -0,0 +1,171 @@ +function decryptNormalMorseManager(inputMessage) { + if(inputMessage === ""){ + return "Please enter at least one character"; + } else { + if (inputMessage.endsWith(" ")) { + inputMessage = inputMessage.substring(0, message.length() - 1); + } + // Variables + var input = inputMessage.toUpperCase(); + if(input.endsWith(' ') == false){ + input = input + " "; + } + while(input.indexOf('\n') != -1){ + input = input.replace("\n","") + } + var inputToSign = input; + var output = ""; + var d = 0; + while ((inputToSign != ' ')) { + d = 0; + var signFull = true; + var sign = ""; + while (signFull) { + if (inputToSign.substring(d, d + 7) == ' '|| inputToSign.substring(d, d + 3) == ' ') { + if (d === 0) { + if (inputToSign.startsWith(" ")) { + output = output + " "; + inputToSign = inputToSign.substring(7, inputToSign.length); + } else { + inputToSign = inputToSign.substring(3, inputToSign.length); + } + } else { + sign = inputToSign.substring(0, d); + inputToSign = inputToSign.substring(d, inputToSign.length); + signFull = false; + } + } else { + d = d + 1; + } + } + if (sign == ".-") { + output = output + "A"; + } else if (sign == "-...") { + output = output + "B"; + } else if (sign == "-.-.") { + output = output + "C"; + } else if (sign == "-..") { + output = output + "D"; + } else if (sign == ".") { + output = output + "E"; + } else if (sign == "..-.") { + output = output + "F"; + } else if (sign == "--.") { + output = output + "G"; + } else if (sign == "....") { + output = output + "H"; + } else if (sign == "..") { + output = output + "I"; + } else if (sign == ".---") { + output = output + "J"; + } else if (sign == "-.-") { + output = output + "K"; + } else if (sign == ".-..") { + output = output + "L"; + } else if (sign == "--") { + output = output + "M"; + } else if (sign == "-.") { + output = output + "N"; + } else if (sign == "---") { + output = output + "O"; + } else if (sign == ".--.") { + output = output + "P"; + } else if (sign == "--.-") { + output = output + "Q"; + } else if (sign == ".-.") { + output = output + "R"; + } else if (sign == "...") { + output = output + "S"; + } else if (sign == "-") { + output = output + "T"; + } else if (sign == "..-") { + output = output + "U"; + } else if (sign == "...-") { + output = output + "V"; + } else if (sign == ".--") { + output = output + "W"; + } else if (sign == "-..-") { + output = output + "X"; + } else if (sign == "-.--") { + output = output + "Y"; + } else if (sign == "--..") { + output = output + "Z"; + } else if (sign == "-----") { + output = output + ". (zero)"; + } else if (sign == ".----") { + output = output + "-"; + } else if (sign == "..---") { + output = output + "2"; + } else if (sign == "...--") { + output = output + "3"; + } else if (sign == "....-") { + output = output + "4"; + } else if (sign == ".....") { + output = output + "5"; + } else if (sign == "-....") { + output = output + "6"; + } else if (sign == "--...") { + output = output + "7"; + } else if (sign == "---..") { + output = output + "8"; + } else if (sign == "----.") { + output = output + "9"; + } else if (sign == ".-.-") { + output = output + "Ä"; + } else if (sign == "---.") { + output = output + "Ö"; + } else if (sign == "..--") { + output = output + "Ü"; + } else if (sign == "...--...") { + output = output + "ß"; + } else if (sign == "----") { + output = output + "CH"; + } else if (sign == ".-.-.-") { + output = output + "."; + } else if (sign == "--..--") { + output = output + ","; + } else if (sign == "---...") { + output = output + ":"; + } else if (sign == "-.-.-.") { + output = output + ";"; + } else if (sign == "..--..") { + output = output + "?"; + } else if (sign == "-.-.--") { + output = output + "!"; + } else if (sign == "-....-") { + output = output + "-"; + } else if (sign == "..--.-") { + output = output + "_"; + } else if (sign == "-.--.") { + output = output + "("; + } else if (sign == "-.--.-") { + output = output + ")"; + } else if (sign == ".----.") { + output = output + "'"; + } else if (sign == "-...-") { + output = output + "="; + } else if (sign == ".-.-.") { + output = output + "+ or End of the signal"; + } else if (sign == "-..-.") { + output = output + "/"; + } else if (sign == ".--.-.") { + output = output + "@"; + } else if (sign == "-.-.-") { + output = output + "Begin of the signal"; + } else if (sign == "-...-") { + output = output + "Wait"; + } else if (sign == "...-.") { + output = output + "Understood"; + } else if (sign == "...-.-") { + output = output + "End of work"; + } else if (sign == "...---...") { + output = output + "SOS"; + } else if (sign == "........") { + output = output + "Error"; + } else { + output = "Code not listed or wrong."; + } + } + return output; + } +} diff --git a/js/engine/DecryptWrittenMorse.js b/js/engine/DecryptWrittenMorse.js index e4dfe25..7551c70 100644 --- a/js/engine/DecryptWrittenMorse.js +++ b/js/engine/DecryptWrittenMorse.js @@ -1,170 +1,169 @@ function decryptWrittenMorseManager(inputMessage) { - if(inputMessage === ""){ - return "Please enter at least one character"; - } else { - if (inputMessage.endsWith(" ")) { - inputMessage = inputMessage.substring(0, message.length() - 1); - } - // Variables - var input = inputMessage.toUpperCase(); - if(input.endsWith('#') == false){ - input = input + "#"; - } - while(input.indexOf('\n') != -1){ - input = input.replace("\n","") - } - var inputToSign = input; - var output = ""; - var d = 0; - while ((inputToSign != '#')) { - d = 0; - var signFull = true; - var sign = ""; - while (signFull) { - if (inputToSign.charAt(d) == '+'|| inputToSign.charAt(d) == '#') { - if (d === 0) { - if (inputToSign.startsWith("+")) { - output = output + " "; - } - inputToSign = inputToSign.substring(1, inputToSign.length); - } else { - sign = inputToSign.substring(0, d); - inputToSign = inputToSign.substring(d, inputToSign.length); - signFull = false; - } - } else { - d = d + 1; - } - } - if (sign == "01") { - output = output + "A"; - } else if (sign == "1000") { - output = output + "B"; - } else if (sign == "1010") { - output = output + "C"; - } else if (sign == "100") { - output = output + "D"; - } else if (sign == "0") { - output = output + "E"; - } else if (sign == "0010") { - output = output + "F"; - } else if (sign == "110") { - output = output + "G"; - } else if (sign == "0000") { - output = output + "H"; - } else if (sign == "00") { - output = output + "I"; - } else if (sign == "0111") { - output = output + "J"; - } else if (sign == "101") { - output = output + "K"; - } else if (sign == "0100") { - output = output + "L"; - } else if (sign == "11") { - output = output + "M"; - } else if (sign == "10") { - output = output + "N"; - } else if (sign == "111") { - output = output + "O"; - } else if (sign == "0110") { - output = output + "P"; - } else if (sign == "1101") { - output = output + "Q"; - } else if (sign == "010") { - output = output + "R"; - } else if (sign == "000") { - output = output + "S"; - } else if (sign == "1") { - output = output + "T"; - } else if (sign == "001") { - output = output + "U"; - } else if (sign == "0001") { - output = output + "V"; - } else if (sign == "011") { - output = output + "W"; - } else if (sign == "1001") { - output = output + "X"; - } else if (sign == "1011") { - output = output + "Y"; - } else if (sign == "1100") { - output = output + "Z"; - } else if (sign == "11111") { - output = output + "0 (zero)"; - } else if (sign == "01111") { - output = output + "1"; - } else if (sign == "00111") { - output = output + "2"; - } else if (sign == "00011") { - output = output + "3"; - } else if (sign == "00001") { - output = output + "4"; - } else if (sign == "00000") { - output = output + "5"; - } else if (sign == "10000") { - output = output + "6"; - } else if (sign == "11000") { - output = output + "7"; - } else if (sign == "11100") { - output = output + "8"; - } else if (sign == "11110") { - output = output + "9"; - } else if (sign == "0101") { - output = output + "Ä"; - } else if (sign == "1110") { - output = output + "Ö"; - } else if (sign == "0011") { - output = output + "Ü"; - } else if (sign == "00011000") { - output = output + "ß"; - } else if (sign == "1111") { - output = output + "CH"; - } else if (sign == "010101") { - output = output + "."; - } else if (sign == "110011") { - output = output + ","; - } else if (sign == "111000") { - output = output + ":"; - } else if (sign == "101010") { - output = output + ";"; - } else if (sign == "001100") { - output = output + "?"; - } else if (sign == "101011") { - output = output + "!"; - } else if (sign == "100001") { - output = output + "-"; - } else if (sign == "001101") { - output = output + "_"; - } else if (sign == "10110") { - output = output + "("; - } else if (sign == "101101") { - output = output + ")"; - } else if (sign == "011110") { - output = output + "'"; - } else if (sign == "10001") { - output = output + "="; - } else if (sign == "01010") { - output = output + "+ or End of the signal"; - } else if (sign == "10010") { - output = output + "/"; - } else if (sign == "011010") { - output = output + "@"; - } else if (sign == "10101") { - output = output + "Begin of the signal"; - } else if (sign == "10001") { - output = output + "Wait"; - } else if (sign == "00010") { - output = output + "Understood"; - } else if (sign == "000101") { - output = output + "End of work"; - } else if (sign == "000111000") { - output = output + "SOS"; - } else if (sign == "00000000") { - output = output + "Error"; - } else { - output = "Code not listed or wrong."; - } - } - return output; + if(inputMessage === ""){ + return "Please enter at least one character"; + } else { + if (inputMessage.endsWith(" ")) { + inputMessage = inputMessage.substring(0, message.length() - 1); } - + // Variables + var input = inputMessage.toUpperCase(); + if(input.endsWith('#') == false){ + input = input + "#"; + } + while(input.indexOf('\n') != -1){ + input = input.replace("\n","") + } + var inputToSign = input; + var output = ""; + var d = 0; + while ((inputToSign != '#')) { + d = 0; + var signFull = true; + var sign = ""; + while (signFull) { + if (inputToSign.charAt(d) == '+'|| inputToSign.charAt(d) == '#') { + if (d === 0) { + if (inputToSign.startsWith("+")) { + output = output + " "; + } + inputToSign = inputToSign.substring(1, inputToSign.length); + } else { + sign = inputToSign.substring(0, d); + inputToSign = inputToSign.substring(d, inputToSign.length); + signFull = false; + } + } else { + d = d + 1; + } + } + if (sign == "01") { + output = output + "A"; + } else if (sign == "1000") { + output = output + "B"; + } else if (sign == "1010") { + output = output + "C"; + } else if (sign == "100") { + output = output + "D"; + } else if (sign == "0") { + output = output + "E"; + } else if (sign == "0010") { + output = output + "F"; + } else if (sign == "110") { + output = output + "G"; + } else if (sign == "0000") { + output = output + "H"; + } else if (sign == "00") { + output = output + "I"; + } else if (sign == "0111") { + output = output + "J"; + } else if (sign == "101") { + output = output + "K"; + } else if (sign == "0100") { + output = output + "L"; + } else if (sign == "11") { + output = output + "M"; + } else if (sign == "10") { + output = output + "N"; + } else if (sign == "111") { + output = output + "O"; + } else if (sign == "0110") { + output = output + "P"; + } else if (sign == "1101") { + output = output + "Q"; + } else if (sign == "010") { + output = output + "R"; + } else if (sign == "000") { + output = output + "S"; + } else if (sign == "1") { + output = output + "T"; + } else if (sign == "001") { + output = output + "U"; + } else if (sign == "0001") { + output = output + "V"; + } else if (sign == "011") { + output = output + "W"; + } else if (sign == "1001") { + output = output + "X"; + } else if (sign == "1011") { + output = output + "Y"; + } else if (sign == "1100") { + output = output + "Z"; + } else if (sign == "11111") { + output = output + "0 (zero)"; + } else if (sign == "01111") { + output = output + "1"; + } else if (sign == "00111") { + output = output + "2"; + } else if (sign == "00011") { + output = output + "3"; + } else if (sign == "00001") { + output = output + "4"; + } else if (sign == "00000") { + output = output + "5"; + } else if (sign == "10000") { + output = output + "6"; + } else if (sign == "11000") { + output = output + "7"; + } else if (sign == "11100") { + output = output + "8"; + } else if (sign == "11110") { + output = output + "9"; + } else if (sign == "0101") { + output = output + "Ä"; + } else if (sign == "1110") { + output = output + "Ö"; + } else if (sign == "0011") { + output = output + "Ü"; + } else if (sign == "00011000") { + output = output + "ß"; + } else if (sign == "1111") { + output = output + "CH"; + } else if (sign == "010101") { + output = output + "."; + } else if (sign == "110011") { + output = output + ","; + } else if (sign == "111000") { + output = output + ":"; + } else if (sign == "101010") { + output = output + ";"; + } else if (sign == "001100") { + output = output + "?"; + } else if (sign == "101011") { + output = output + "!"; + } else if (sign == "100001") { + output = output + "-"; + } else if (sign == "001101") { + output = output + "_"; + } else if (sign == "10110") { + output = output + "("; + } else if (sign == "101101") { + output = output + ")"; + } else if (sign == "011110") { + output = output + "'"; + } else if (sign == "10001") { + output = output + "="; + } else if (sign == "01010") { + output = output + "+ or End of the signal"; + } else if (sign == "10010") { + output = output + "/"; + } else if (sign == "011010") { + output = output + "@"; + } else if (sign == "10101") { + output = output + "Begin of the signal"; + } else if (sign == "10001") { + output = output + "Wait"; + } else if (sign == "00010") { + output = output + "Understood"; + } else if (sign == "000101") { + output = output + "End of work"; + } else if (sign == "000111000") { + output = output + "SOS"; + } else if (sign == "00000000") { + output = output + "Error"; + } else { + output = "Code not listed or wrong."; + } + } + return output; + } } diff --git a/js/web/web.js b/js/web/web.js index af1fce6..3fe87cf 100644 --- a/js/web/web.js +++ b/js/web/web.js @@ -35,7 +35,7 @@ function decrypt(){ $('#output').text(decryptWrittenMorseManager(input)) } else { //TODO port the normal morse decode engine - $("#output").text("The normal morse engine is not ported jet.") + $("#output").text(decryptNormalMorseManager(input)) } $('#outputcard').fadeIn(dur) }