Included writtenMorse encoding engine
This commit is contained in:
parent
d99316aec7
commit
945b5838e1
3 changed files with 166 additions and 1 deletions
|
@ -12,6 +12,7 @@
|
||||||
|
|
||||||
<script src="js/web/web.js"></script>
|
<script src="js/web/web.js"></script>
|
||||||
<script src="js/engine/DecodeWrittenMorse.js"></script>
|
<script src="js/engine/DecodeWrittenMorse.js"></script>
|
||||||
|
<script src="js/engine/EncodeWrittenMorse.js"></script>
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
164
js/engine/EncodeWrittenMorse.js
Normal file
164
js/engine/EncodeWrittenMorse.js
Normal file
|
@ -0,0 +1,164 @@
|
||||||
|
function encodeWrittenMorseManager(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() + "#";
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -21,7 +21,7 @@ function drawer(){
|
||||||
function encode(){
|
function encode(){
|
||||||
var input = $('#textarea').val()
|
var input = $('#textarea').val()
|
||||||
if(wm){
|
if(wm){
|
||||||
$("#output").text("The normal morse engine is not ported jet.")
|
$("#output").text(encodeWrittenMorseManager(input))
|
||||||
} else {
|
} else {
|
||||||
//TODO port the normal morse decode engine
|
//TODO port the normal morse decode engine
|
||||||
$("#output").text("The normal morse engine is not ported jet.")
|
$("#output").text("The normal morse engine is not ported jet.")
|
||||||
|
|
Reference in a new issue