line intend fixes, add normal morse decryption

This commit is contained in:
mmk2410 2015-04-16 23:00:13 +02:00
parent 4d6006e99b
commit 0e78a407e5
4 changed files with 339 additions and 168 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/DecryptNormalMorse.js"></script>
</head>
<body>

View 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;
}
}

View file

@ -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;
}
}

View file

@ -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)
}