line intend fixes, add normal morse decryption
This commit is contained in:
parent
4d6006e99b
commit
0e78a407e5
4 changed files with 339 additions and 168 deletions
|
@ -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/DecryptNormalMorse.js"></script>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
|
171
js/engine/DecryptNormalMorse.js
Normal file
171
js/engine/DecryptNormalMorse.js
Normal file
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -166,5 +166,4 @@ function decryptWrittenMorseManager(inputMessage) {
|
|||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Reference in a new issue