Version 0.2 beta

This is the beta version of the Morse Converter for the web. It is a complete rewrite and now a full webapp using Polymer. It supports all the features of the desktop and the android version.
This commit is contained in:
mmk2410 2015-08-29 23:16:45 +02:00
parent 0e7a53c678
commit febe5a9eec
35 changed files with 2499 additions and 2052 deletions

View file

@ -0,0 +1,59 @@
isNormalMorseCode = (input) ->
input = input.toLowerCase()
return !(input.indexOf("a") > -1 or input.indexOf("b") > -1 or
input.indexOf("c") > -1 or input.indexOf("d") > -1 or
input.indexOf("e") > -1 or input.indexOf("f") > -1 or
input.indexOf("g") > -1 or input.indexOf("h") > -1 or
input.indexOf("i") > -1 or input.indexOf("j") > -1 or
input.indexOf("k") > -1 or input.indexOf("l") > -1 or
input.indexOf("m") > -1 or input.indexOf("n") > -1 or
input.indexOf("o") > -1 or input.indexOf("p") > -1 or
input.indexOf("q") > -1 or input.indexOf("r") > -1 or
input.indexOf("s") > -1 or input.indexOf("t") > -1 or
input.indexOf("u") > -1 or input.indexOf("v") > -1 or
input.indexOf("w") > -1 or input.indexOf("x") > -1 or
input.indexOf("y") > -1 or input.indexOf("z") > -1 or
input.indexOf("0") > -1 or input.indexOf("1") > -1 or
input.indexOf("2") > -1 or input.indexOf("3") > -1 or
input.indexOf("4") > -1 or input.indexOf("5") > -1 or
input.indexOf("6") > -1 or input.indexOf("7") > -1 or
input.indexOf("8") > -1 or input.indexOf("9") > -1 or
input.indexOf("Ä") > -1 or input.indexOf("Ö") > -1 or
input.indexOf("Ü") > -1 or input.indexOf("ß") > -1 or
input.indexOf("$") > -1 or input.indexOf(",") > -1 or
input.indexOf(":") > -1 or input.indexOf(";") > -1 or
input.indexOf("!") > -1 or input.indexOf("?") > -1 or
input.indexOf("+") > -1 or input.indexOf("_") > -1 or
input.indexOf("(") > -1 or input.indexOf(")") > -1 or
input.indexOf("=") > -1 or input.indexOf("/") > -1 or
input.indexOf("@") > -1 or input.indexOf("'") > -1)
isWrittenMorseCode = (input) ->
input = input.toLowerCase()
return not (input.indexOf("a") > -1 or input.indexOf("b") > -1 or
input.indexOf("c") > -1 or input.indexOf("d") > -1 or
input.indexOf("e") > -1 or input.indexOf("f") > -1 or
input.indexOf("g") > -1 or input.indexOf("h") > -1 or
input.indexOf("i") > -1 or input.indexOf("j") > -1 or
input.indexOf("k") > -1 or input.indexOf("l") > -1 or
input.indexOf("m") > -1 or input.indexOf("n") > -1 or
input.indexOf("o") > -1 or input.indexOf("p") > -1 or
input.indexOf("q") > -1 or input.indexOf("r") > -1 or
input.indexOf("s") > -1 or input.indexOf("t") > -1 or
input.indexOf("u") > -1 or input.indexOf("v") > -1 or
input.indexOf("w") > -1 or input.indexOf("x") > -1 or
input.indexOf("y") > -1 or input.indexOf("z") > -1 or
input.indexOf("2") > -1 or input.indexOf("3") > -1 or
input.indexOf("4") > -1 or input.indexOf("5") > -1 or
input.indexOf("6") > -1 or input.indexOf("7") > -1 or
input.indexOf("8") > -1 or input.indexOf("9") > -1 or
input.indexOf("Ä") > -1 or input.indexOf("Ö") > -1 or
input.indexOf("Ü") > -1 or input.indexOf("ß") > -1 or
input.indexOf(".") > -1 or input.indexOf(",") > -1 or
input.indexOf(":") > -1 or input.indexOf(";") > -1 or
input.indexOf("!") > -1 or input.indexOf("?") > -1 or
input.indexOf("-") > -1 or input.indexOf("_") > -1 or
input.indexOf("(") > -1 or input.indexOf(")") > -1 or
input.indexOf("=") > -1 or input.indexOf("/") > -1 or
input.indexOf("@") > -1 or input.indexOf("'") > -1 or
input.indexOf("$") > -1)

View file

@ -0,0 +1,11 @@
var isNormalMorseCode, isWrittenMorseCode;
isNormalMorseCode = function(input) {
input = input.toLowerCase();
return !(input.indexOf("a") > -1 || input.indexOf("b") > -1 || input.indexOf("c") > -1 || input.indexOf("d") > -1 || input.indexOf("e") > -1 || input.indexOf("f") > -1 || input.indexOf("g") > -1 || input.indexOf("h") > -1 || input.indexOf("i") > -1 || input.indexOf("j") > -1 || input.indexOf("k") > -1 || input.indexOf("l") > -1 || input.indexOf("m") > -1 || input.indexOf("n") > -1 || input.indexOf("o") > -1 || input.indexOf("p") > -1 || input.indexOf("q") > -1 || input.indexOf("r") > -1 || input.indexOf("s") > -1 || input.indexOf("t") > -1 || input.indexOf("u") > -1 || input.indexOf("v") > -1 || input.indexOf("w") > -1 || input.indexOf("x") > -1 || input.indexOf("y") > -1 || input.indexOf("z") > -1 || input.indexOf("0") > -1 || input.indexOf("1") > -1 || input.indexOf("2") > -1 || input.indexOf("3") > -1 || input.indexOf("4") > -1 || input.indexOf("5") > -1 || input.indexOf("6") > -1 || input.indexOf("7") > -1 || input.indexOf("8") > -1 || input.indexOf("9") > -1 || input.indexOf("Ä") > -1 || input.indexOf("Ö") > -1 || input.indexOf("Ü") > -1 || input.indexOf("ß") > -1 || input.indexOf("$") > -1 || input.indexOf(",") > -1 || input.indexOf(":") > -1 || input.indexOf(";") > -1 || input.indexOf("!") > -1 || input.indexOf("?") > -1 || input.indexOf("+") > -1 || input.indexOf("_") > -1 || input.indexOf("(") > -1 || input.indexOf(")") > -1 || input.indexOf("=") > -1 || input.indexOf("/") > -1 || input.indexOf("@") > -1 || input.indexOf("'") > -1);
};
isWrittenMorseCode = function(input) {
input = input.toLowerCase();
return !(input.indexOf("a") > -1 || input.indexOf("b") > -1 || input.indexOf("c") > -1 || input.indexOf("d") > -1 || input.indexOf("e") > -1 || input.indexOf("f") > -1 || input.indexOf("g") > -1 || input.indexOf("h") > -1 || input.indexOf("i") > -1 || input.indexOf("j") > -1 || input.indexOf("k") > -1 || input.indexOf("l") > -1 || input.indexOf("m") > -1 || input.indexOf("n") > -1 || input.indexOf("o") > -1 || input.indexOf("p") > -1 || input.indexOf("q") > -1 || input.indexOf("r") > -1 || input.indexOf("s") > -1 || input.indexOf("t") > -1 || input.indexOf("u") > -1 || input.indexOf("v") > -1 || input.indexOf("w") > -1 || input.indexOf("x") > -1 || input.indexOf("y") > -1 || input.indexOf("z") > -1 || input.indexOf("2") > -1 || input.indexOf("3") > -1 || input.indexOf("4") > -1 || input.indexOf("5") > -1 || input.indexOf("6") > -1 || input.indexOf("7") > -1 || input.indexOf("8") > -1 || input.indexOf("9") > -1 || input.indexOf("Ä") > -1 || input.indexOf("Ö") > -1 || input.indexOf("Ü") > -1 || input.indexOf("ß") > -1 || input.indexOf(".") > -1 || input.indexOf(",") > -1 || input.indexOf(":") > -1 || input.indexOf(";") > -1 || input.indexOf("!") > -1 || input.indexOf("?") > -1 || input.indexOf("-") > -1 || input.indexOf("_") > -1 || input.indexOf("(") > -1 || input.indexOf(")") > -1 || input.indexOf("=") > -1 || input.indexOf("/") > -1 || input.indexOf("@") > -1 || input.indexOf("'") > -1 || input.indexOf("$") > -1);
};

114
app/scripts/app.js Normal file
View file

@ -0,0 +1,114 @@
(function (document) {
'use strict';
var app = document.querySelector('#app');
app.displayInstalledToast = function() {
document.querySelector('#caching-complete').show();
};
app.addEventListener('template-bound', function() {
console.log("Marcel Kapfer (mmk2410)");
console.log("Morse Converter beta");
console.log("Version 0.2");
});
window.addEventListener('WebComponentsReady', function() {
document.querySelector('body').removeAttribute('unresolved');
// Ensure that the drawer is always hidden
var drawerPanel = document.querySelector('#paperDrawerPanel');
drawerPanel.forceNarrow = true;
// initialize the app
var inputArea, menuAbout, menuFork, menuNormalMorse, menuReportBug, menuWrittenMorse, outputArea, outputPaper, toastNormalMorse, toastWrittenMorse, writtenMorse;
writtenMorse = true;
toastWrittenMorse = document.querySelector('#toastWrittenMorse');
toastNormalMorse = document.querySelector('#toastNormalMorse');
inputArea = document.querySelector('#inputArea');
outputArea = document.querySelector('#outputArea');
outputPaper = document.querySelector('#outputPaper');
menuWrittenMorse = document.querySelector('#menuWrittenMorse');
menuWrittenMorse.addEventListener('click', function() {
writtenMorse = true;
fadeOut(outputPaper);
inputArea.value = "";
drawerPanel.closeDrawer();
toastWrittenMorse.toggle();
});
menuNormalMorse = document.querySelector('#menuNormalMorse');
menuNormalMorse.addEventListener('click', function() {
writtenMorse = false;
fadeOut(outputPaper);
inputArea.value = "";
drawerPanel.closeDrawer();
toastNormalMorse.toggle();
});
menuReportBug = document.querySelector('#menuReportBug');
menuReportBug.addEventListener('click', function() {
window.open("https://github.com/mmk2410/morse-converter-web/issues", "_blank");
drawerPanel.closeDrawer();
});
menuAbout = document.querySelector('#menuAbout');
menuAbout.addEventListener('click', function() {
window.open("https://marcel-kapfer.de/writtenmorse", "_blank");
drawerPanel.closeDrawer();
});
menuFork = document.querySelector('#menuFork');
menuFork.addEventListener('click', function() {
window.open("https://github.com/mmk2410/morse-converter-web/", "_blank");
drawerPanel.closeDrawer();
});
inputArea.addEventListener('keyup', function() {
var string;
if (input.value.trim()) {
if(outputPaper.style.display == 'none') {
fadeIn(outputPaper);
}
if (writtenMorse) {
if (isWrittenMorseCode(input.value)) {
string = getWrittenMorseEncoded(input.value);
} else {
string = getWrittenMorseDecoded(input.value);
}
} else {
if (isNormalMorseCode(input.value)) {
string = getNormalMorseEncoded(input.value);
} else {
string = getNormalMorseDecoded(input.value);
}
}
outputArea.innerHTML = string;
} else {
fadeOut(outputPaper);
}
});
});
})(document);
function fadeOut(element) {
var op = 1; // initial opacity
var timer = setInterval(function () {
if (op <= 0.1){
clearInterval(timer);
element.style.display = 'none';
}
element.style.opacity = op;
element.style.filter = 'alpha(opacity=' + op * 100 + ")";
op -= op * 0.1;
}, 10);
}
function fadeIn(element) {
var op = 0.1; // initial opacity
element.style.display = 'block';
var timer = setInterval(function () {
if (op >= 1){
clearInterval(timer);
}
element.style.opacity = op;
element.style.filter = 'alpha(opacity=' + op * 100 + ")";
op += op * 0.1;
}, 10);
}

View file

@ -0,0 +1,522 @@
getNormalMorseDecoded = (input) ->
# Well, this shouldn't happen...
if !(input)
return null
# remove trailing whitspaces
if input.charAt input.length is " "
input.substring 0, input.length - 1
input = input.toUpperCase()
output = ""
# Return special signs
if input is "LETTERSPACE"
return "&nbsp;&nbsp;&nbsp;"
else if input is "END OF WORK"
return "...-.-"
else if input is "ERROR"
return "........"
else if input is "STARTING SIGNAL"
return "-.-.-"
else if input is "ENDING SIGNAL"
return ".-.-."
else if input is "UNDERSTOOD"
return "...-."
else if input is "WAIT"
return ".-..."
else if input is "SOS"
return "...---..."
else if input is "LETTER SPACE"
return "&nbsp;&nbsp;&nbsp;"
else if input is "WORD SPACE"
return "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
else # the converting part
while input.length > 0
if input.charAt(0) is " "
if output.charAt(output.length) is " "
output = output.substring 0, output.length - 1
output += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
input = input.substring 1
else if input.charAt(0) is "\n"
output += "<br>"
input = input.substring 1
else if input.charAt(0) is "A"
output += ".-&nbsp;&nbsp;&nbsp;"
input = input.substring 1
else if input.charAt(0) is "B"
output += "-...&nbsp;&nbsp;&nbsp;"
input = input.substring 1
else if input.charAt(0) is "C"
output += "-.-.&nbsp;&nbsp;&nbsp;"
input = input.substring 1
else if input.charAt(0) is "D"
output += "-..&nbsp;&nbsp;&nbsp;"
input = input.substring 1
else if input.charAt(0) is "E"
output += ".&nbsp;&nbsp;&nbsp;"
input = input.substring 1
else if input.charAt(0) is "F"
output += "..-.&nbsp;&nbsp;&nbsp;"
input = input.substring 1
else if input.charAt(0) is "G"
output += "--.&nbsp;&nbsp;&nbsp;"
input = input.substring 1
else if input.charAt(0) is "H"
output += "....&nbsp;&nbsp;&nbsp;"
input = input.substring 1
else if input.charAt(0) is "I"
output += "..&nbsp;&nbsp;&nbsp;"
input = input.substring 1
else if input.charAt(0) is "J"
output += ".---&nbsp;&nbsp;&nbsp;"
input = input.substring 1
else if input.charAt(0) is "K"
output += "-.-&nbsp;&nbsp;&nbsp;"
input = input.substring 1
else if input.charAt(0) is "L"
output += ".-..&nbsp;&nbsp;&nbsp;"
input = input.substring 1
else if input.charAt(0) is "M"
output += "--&nbsp;&nbsp;&nbsp;"
input = input.substring 1
else if input.charAt(0) is "N"
output += "-.&nbsp;&nbsp;&nbsp;"
input = input.substring 1
else if input.charAt(0) is "O"
output += "---&nbsp;&nbsp;&nbsp;"
input = input.substring 1
else if input.charAt(0) is "P"
output += ".--.&nbsp;&nbsp;&nbsp;"
input = input.substring 1
else if input.charAt(0) is "Q"
output += "--.-&nbsp;&nbsp;&nbsp;"
input = input.substring 1
else if input.charAt(0) is "R"
output += ".-.&nbsp;&nbsp;&nbsp;"
input = input.substring 1
else if input.charAt(0) is "S"
output += "...&nbsp;&nbsp;&nbsp;"
input = input.substring 1
else if input.charAt(0) is "T"
output += "-&nbsp;&nbsp;&nbsp;"
input = input.substring 1
else if input.charAt(0) is "U"
output += "..-&nbsp;&nbsp;&nbsp;"
input = input.substring 1
else if input.charAt(0) is "V"
output += "...-&nbsp;&nbsp;&nbsp;"
input = input.substring 1
else if input.charAt(0) is "W"
output += ".--&nbsp;&nbsp;&nbsp;"
input = input.substring 1
else if input.charAt(0) is "X"
output += "-..-&nbsp;&nbsp;&nbsp;"
input = input.substring 1
else if input.charAt(0) is "Y"
output += "-.--&nbsp;&nbsp;&nbsp;"
input = input.substring 1
else if input.charAt(0) is "Z"
output += "--..&nbsp;&nbsp;&nbsp;"
input = input.substring 1
else if input.charAt(0) is "0"
output += "-----&nbsp;&nbsp;&nbsp;"
input = input.substring 1
else if input.charAt(0) is "1"
output += ".----&nbsp;&nbsp;&nbsp;"
input = input.substring 1
else if input.charAt(0) is "2"
output += "..---&nbsp;&nbsp;&nbsp;"
input = input.substring 1
else if input.charAt(0) is "3"
output += "...--&nbsp;&nbsp;&nbsp;"
input = input.substring 1
else if input.charAt(0) is "4"
output += "....-&nbsp;&nbsp;&nbsp;"
input = input.substring 1
else if input.charAt(0) is "5"
output += ".....&nbsp;&nbsp;&nbsp;"
input = input.substring 1
else if input.charAt(0) is "6"
output += "-....&nbsp;&nbsp;&nbsp;"
input = input.substring 1
else if input.charAt(0) is "7"
output += "--...&nbsp;&nbsp;&nbsp;"
input = input.substring 1
else if input.charAt(0) is "8"
output += "---..&nbsp;&nbsp;&nbsp;"
input = input.substring 1
else if input.charAt(0) is "9"
output += "----.&nbsp;&nbsp;&nbsp;"
input = input.substring 1
else if input.charAt(0) is "Ä"
output += ".-.-&nbsp;&nbsp;&nbsp;"
input = input.substring 1
else if input.charAt(0) is "Ö"
output += "---.&nbsp;&nbsp;&nbsp;"
input = input.substring 1
else if input.charAt(0) is "Ü"
output += "..--&nbsp;&nbsp;&nbsp;"
input = input.substring 1
else if input.charAt(0) is "ß"
output += "...--...&nbsp;&nbsp;&nbsp;"
input = input.substring 1
else if input.charAt(0) is "."
output += ".-.-.-&nbsp;&nbsp;&nbsp;"
input = input.substring 1
else if input.charAt(0) is ","
output += "--..--&nbsp;&nbsp;&nbsp;"
input = input.substring 1
else if input.charAt(0) is ":"
output += "---...&nbsp;&nbsp;&nbsp;"
input = input.substring 1
else if input.charAt(0) is ""
output += "-.-.-.&nbsp;&nbsp;&nbsp;"
input = input.substring 1
else if input.charAt(0) is "?"
output += "..--..&nbsp;&nbsp;&nbsp;"
input = input.substring 1
else if input.charAt(0) is "!"
output += "-.-.--&nbsp;&nbsp;&nbsp;"
input = input.substring 1
else if input.charAt(0) is "-"
output += "-....-&nbsp;&nbsp;&nbsp;"
input = input.substring 1
else if input.charAt(0) is "_"
output += "..--.-&nbsp;&nbsp;&nbsp;"
input = input.substring 1
else if input.charAt(0) is "("
output += "-.--.&nbsp;&nbsp;&nbsp;"
input = input.substring 1
else if input.charAt(0) is ")"
output += "-.--.-&nbsp;&nbsp;&nbsp;"
input = input.substring 1
else if input.charAt(0) is "="
output += "-...-&nbsp;&nbsp;&nbsp;"
input = input.substring 1
else if input.charAt(0) is "+"
output += ".-.-.&nbsp;&nbsp;&nbsp;"
input = input.substring 1
else if input.charAt(0) is "/"
output += "-..-.&nbsp;&nbsp;&nbsp;"
input = input.substring 1
else if input.charAt(0) is "@"
output += ".--.-.&nbsp;&nbsp;&nbsp;"
input = input.substring 1
else if input.charAt(0) is "'"
output += ".----.&nbsp;&nbsp;&nbsp;"
input = input.substring 1
else if input.charAt(0) is "$"
output += "...-..-&nbsp;&nbsp;&nbsp;"
input = input.substring 1
else
return "Code not listed or wrong."
if output.charAt(output.length - 1) is " "
output = output.substring 0, output.length - 1
return output
getNormalMorseEncoded = (input) ->
# Well, this shouldn't happen...
if !(input) then return null
# remove trailing whitspaces
while input.charAt(input.length - 1) is " "
input = input.substring 0, input.length - 1
input = input.toUpperCase()
# remove all trailing new lines
while input.charAt(input.length - 1) is "\n"
input = input.substring 0, input.length - 1
# add one letterspace to the input
input += " "
inputToSign = input
output = ""
while inputToSign isnt " "
d = 0
signFull = true
sign = ""
while signFull
if inputToSign.substring(d, d + 7) is " " or
inputToSign.substring(d, d + 3) is " " or
inputToSign.charAt(0) is "\n"
if d is 0
if inputToSign.substring(0, 7) is " "
output += " "
inputToSign = inputToSign.substring 7, inputToSign.length
if inputToSign.substring(0, 3) is " "
inputToSign = inputToSign.substring 3, inputToSign.length
if inputToSign.charAt(0) is "\n"
output += "<br>"
inputToSign = inputToSign.substring 1, inputToSign.length
else
sign = inputToSign.substring 0, d
inputToSign = inputToSign.substring d, inputToSign.length
signFull = false
else
d++
if sign is ".-"
output += "A"
else if sign is "-..."
output += "B"
else if sign is "-.-."
output += "C"
else if sign is "-.."
output += "D"
else if sign is "."
output += "E"
else if sign is "..-."
output += "F"
else if sign is "--."
output += "G"
else if sign is "...."
output += "H"
else if sign is ".."
output += "I"
else if sign is ".---"
output += "J"
else if sign is "-.-"
output += "K"
else if sign is ".-.."
output += "L"
else if sign is "--"
output += "M"
else if sign is "-."
output += "N"
else if sign is "---"
output += "O"
else if sign is ".--."
output += "P"
else if sign is "--.-"
output += "Q"
else if sign is ".-."
output += "R"
else if sign is "..."
output += "S"
else if sign is "-"
output += "T"
else if sign is "..-"
output += "U"
else if sign is "...-"
output += "V"
else if sign is ".--"
output += "W"
else if sign is "-..-"
output += "X"
else if sign is "-.--"
output += "Y"
else if sign is "--.."
output += "Z"
else if sign is "-----"
output += "0"
else if sign is ".----"
output += "1"
else if sign is "..---"
output += "2"
else if sign is "...--"
output += "3"
else if sign is "....-"
output += "4"
else if sign is "....."
output += "5"
else if sign is "-...."
output += "6"
else if sign is "--..."
output += "7"
else if sign is "---.."
output += "8"
else if sign is "----."
output += "9"
else if sign is ".-.-"
output += "Ä"
else if sign is "---."
output += "Ö"
else if sign is "..--"
output += "Ü"
else if sign is "...--..."
output += "ß"
else if sign is "----"
output += "CH"
else if sign is ".-.-.-"
output += "."
else if sign is "--..--"
output += ","
else if sign is "---..."
output += ":"
else if sign is "-.-.-."
output += ";"
else if sign is "..--.."
output += "?"
else if sign is "-.-.--"
output += "!"
else if sign is "-....-"
output += "-"
else if sign is "..--.-"
output += "_"
else if sign is "-.--."
output += "("
else if sign is "-.--.-"
output += ")"
else if sign is ".----."
output += "'"
else if sign is "-...-"
output += "="
else if sign is ".-.-."
output += "+"
else if sign is "-..-."
output += "/"
else if sign is ".--.-."
output += "@"
else if sign is "-.-.-"
output += "Begin of the signal"
else if sign is "-...-"
output += "Wait"
else if sign is "...-."
output += "Understood"
else if sign is "...-.-"
output += "End of work"
else if sign is "...---..."
output += "SOS"
else if sign is "........"
output += "Error"
else
return "Code not listed or wrong."
return output

View file

@ -0,0 +1,394 @@
var getNormalMorseDecoded, getNormalMorseEncoded;
getNormalMorseDecoded = function(input) {
var output;
if (!input) {
return null;
}
if (input.charAt(input.length === " ")) {
input.substring(0, input.length - 1);
}
input = input.toUpperCase();
output = "";
if (input === "LETTERSPACE") {
return "&nbsp;&nbsp;&nbsp;";
} else if (input === "END OF WORK") {
return "...-.-";
} else if (input === "ERROR") {
return "........";
} else if (input === "STARTING SIGNAL") {
return "-.-.-";
} else if (input === "ENDING SIGNAL") {
return ".-.-.";
} else if (input === "UNDERSTOOD") {
return "...-.";
} else if (input === "WAIT") {
return ".-...";
} else if (input === "SOS") {
return "...---...";
} else if (input === "LETTER SPACE") {
return "&nbsp;&nbsp;&nbsp;";
} else if (input === "WORD SPACE") {
return "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
} else {
while (input.length > 0) {
if (input.charAt(0) === " ") {
if (output.charAt(output.length) === " ") {
output = output.substring(0, output.length - 1);
}
output += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
input = input.substring(1);
} else if (input.charAt(0) === "\n") {
output += "<br>";
input = input.substring(1);
} else if (input.charAt(0) === "A") {
output += ".-&nbsp;&nbsp;&nbsp;";
input = input.substring(1);
} else if (input.charAt(0) === "B") {
output += "-...&nbsp;&nbsp;&nbsp;";
input = input.substring(1);
} else if (input.charAt(0) === "C") {
output += "-.-.&nbsp;&nbsp;&nbsp;";
input = input.substring(1);
} else if (input.charAt(0) === "D") {
output += "-..&nbsp;&nbsp;&nbsp;";
input = input.substring(1);
} else if (input.charAt(0) === "E") {
output += ".&nbsp;&nbsp;&nbsp;";
input = input.substring(1);
} else if (input.charAt(0) === "F") {
output += "..-.&nbsp;&nbsp;&nbsp;";
input = input.substring(1);
} else if (input.charAt(0) === "G") {
output += "--.&nbsp;&nbsp;&nbsp;";
input = input.substring(1);
} else if (input.charAt(0) === "H") {
output += "....&nbsp;&nbsp;&nbsp;";
input = input.substring(1);
} else if (input.charAt(0) === "I") {
output += "..&nbsp;&nbsp;&nbsp;";
input = input.substring(1);
} else if (input.charAt(0) === "J") {
output += ".---&nbsp;&nbsp;&nbsp;";
input = input.substring(1);
} else if (input.charAt(0) === "K") {
output += "-.-&nbsp;&nbsp;&nbsp;";
input = input.substring(1);
} else if (input.charAt(0) === "L") {
output += ".-..&nbsp;&nbsp;&nbsp;";
input = input.substring(1);
} else if (input.charAt(0) === "M") {
output += "--&nbsp;&nbsp;&nbsp;";
input = input.substring(1);
} else if (input.charAt(0) === "N") {
output += "-.&nbsp;&nbsp;&nbsp;";
input = input.substring(1);
} else if (input.charAt(0) === "O") {
output += "---&nbsp;&nbsp;&nbsp;";
input = input.substring(1);
} else if (input.charAt(0) === "P") {
output += ".--.&nbsp;&nbsp;&nbsp;";
input = input.substring(1);
} else if (input.charAt(0) === "Q") {
output += "--.-&nbsp;&nbsp;&nbsp;";
input = input.substring(1);
} else if (input.charAt(0) === "R") {
output += ".-.&nbsp;&nbsp;&nbsp;";
input = input.substring(1);
} else if (input.charAt(0) === "S") {
output += "...&nbsp;&nbsp;&nbsp;";
input = input.substring(1);
} else if (input.charAt(0) === "T") {
output += "-&nbsp;&nbsp;&nbsp;";
input = input.substring(1);
} else if (input.charAt(0) === "U") {
output += "..-&nbsp;&nbsp;&nbsp;";
input = input.substring(1);
} else if (input.charAt(0) === "V") {
output += "...-&nbsp;&nbsp;&nbsp;";
input = input.substring(1);
} else if (input.charAt(0) === "W") {
output += ".--&nbsp;&nbsp;&nbsp;";
input = input.substring(1);
} else if (input.charAt(0) === "X") {
output += "-..-&nbsp;&nbsp;&nbsp;";
input = input.substring(1);
} else if (input.charAt(0) === "Y") {
output += "-.--&nbsp;&nbsp;&nbsp;";
input = input.substring(1);
} else if (input.charAt(0) === "Z") {
output += "--..&nbsp;&nbsp;&nbsp;";
input = input.substring(1);
} else if (input.charAt(0) === "0") {
output += "-----&nbsp;&nbsp;&nbsp;";
input = input.substring(1);
} else if (input.charAt(0) === "1") {
output += ".----&nbsp;&nbsp;&nbsp;";
input = input.substring(1);
} else if (input.charAt(0) === "2") {
output += "..---&nbsp;&nbsp;&nbsp;";
input = input.substring(1);
} else if (input.charAt(0) === "3") {
output += "...--&nbsp;&nbsp;&nbsp;";
input = input.substring(1);
} else if (input.charAt(0) === "4") {
output += "....-&nbsp;&nbsp;&nbsp;";
input = input.substring(1);
} else if (input.charAt(0) === "5") {
output += ".....&nbsp;&nbsp;&nbsp;";
input = input.substring(1);
} else if (input.charAt(0) === "6") {
output += "-....&nbsp;&nbsp;&nbsp;";
input = input.substring(1);
} else if (input.charAt(0) === "7") {
output += "--...&nbsp;&nbsp;&nbsp;";
input = input.substring(1);
} else if (input.charAt(0) === "8") {
output += "---..&nbsp;&nbsp;&nbsp;";
input = input.substring(1);
} else if (input.charAt(0) === "9") {
output += "----.&nbsp;&nbsp;&nbsp;";
input = input.substring(1);
} else if (input.charAt(0) === "Ä") {
output += ".-.-&nbsp;&nbsp;&nbsp;";
input = input.substring(1);
} else if (input.charAt(0) === "Ö") {
output += "---.&nbsp;&nbsp;&nbsp;";
input = input.substring(1);
} else if (input.charAt(0) === "Ü") {
output += "..--&nbsp;&nbsp;&nbsp;";
input = input.substring(1);
} else if (input.charAt(0) === "ß") {
output += "...--...&nbsp;&nbsp;&nbsp;";
input = input.substring(1);
} else if (input.charAt(0) === ".") {
output += ".-.-.-&nbsp;&nbsp;&nbsp;";
input = input.substring(1);
} else if (input.charAt(0) === ",") {
output += "--..--&nbsp;&nbsp;&nbsp;";
input = input.substring(1);
} else if (input.charAt(0) === ":") {
output += "---...&nbsp;&nbsp;&nbsp;";
input = input.substring(1);
} else if (input.charAt(0) === "") {
output += "-.-.-.&nbsp;&nbsp;&nbsp;";
input = input.substring(1);
} else if (input.charAt(0) === "?") {
output += "..--..&nbsp;&nbsp;&nbsp;";
input = input.substring(1);
} else if (input.charAt(0) === "!") {
output += "-.-.--&nbsp;&nbsp;&nbsp;";
input = input.substring(1);
} else if (input.charAt(0) === "-") {
output += "-....-&nbsp;&nbsp;&nbsp;";
input = input.substring(1);
} else if (input.charAt(0) === "_") {
output += "..--.-&nbsp;&nbsp;&nbsp;";
input = input.substring(1);
} else if (input.charAt(0) === "(") {
output += "-.--.&nbsp;&nbsp;&nbsp;";
input = input.substring(1);
} else if (input.charAt(0) === ")") {
output += "-.--.-&nbsp;&nbsp;&nbsp;";
input = input.substring(1);
} else if (input.charAt(0) === "=") {
output += "-...-&nbsp;&nbsp;&nbsp;";
input = input.substring(1);
} else if (input.charAt(0) === "+") {
output += ".-.-.&nbsp;&nbsp;&nbsp;";
input = input.substring(1);
} else if (input.charAt(0) === "/") {
output += "-..-.&nbsp;&nbsp;&nbsp;";
input = input.substring(1);
} else if (input.charAt(0) === "@") {
output += ".--.-.&nbsp;&nbsp;&nbsp;";
input = input.substring(1);
} else if (input.charAt(0) === "'") {
output += ".----.&nbsp;&nbsp;&nbsp;";
input = input.substring(1);
} else if (input.charAt(0) === "$") {
output += "...-..-&nbsp;&nbsp;&nbsp;";
input = input.substring(1);
} else {
return "Code not listed or wrong.";
}
}
if (output.charAt(output.length - 1) === " ") {
output = output.substring(0, output.length - 1);
}
}
return output;
};
getNormalMorseEncoded = function(input) {
var d, inputToSign, output, sign, signFull;
if (!input) {
return null;
}
while (input.charAt(input.length - 1) === " ") {
input = input.substring(0, input.length - 1);
}
input = input.toUpperCase();
while (input.charAt(input.length - 1) === "\n") {
input = input.substring(0, input.length - 1);
}
input += " ";
inputToSign = input;
output = "";
while (inputToSign !== " ") {
d = 0;
signFull = true;
sign = "";
while (signFull) {
if (inputToSign.substring(d, d + 7) === " " || inputToSign.substring(d, d + 3) === " " || inputToSign.charAt(0) === "\n") {
if (d === 0) {
if (inputToSign.substring(0, 7) === " ") {
output += " ";
inputToSign = inputToSign.substring(7, inputToSign.length);
}
if (inputToSign.substring(0, 3) === " ") {
inputToSign = inputToSign.substring(3, inputToSign.length);
}
if (inputToSign.charAt(0) === "\n") {
output += "<br>";
inputToSign = inputToSign.substring(1, inputToSign.length);
}
} else {
sign = inputToSign.substring(0, d);
inputToSign = inputToSign.substring(d, inputToSign.length);
signFull = false;
}
} else {
d++;
}
}
if (sign === ".-") {
output += "A";
} else if (sign === "-...") {
output += "B";
} else if (sign === "-.-.") {
output += "C";
} else if (sign === "-..") {
output += "D";
} else if (sign === ".") {
output += "E";
} else if (sign === "..-.") {
output += "F";
} else if (sign === "--.") {
output += "G";
} else if (sign === "....") {
output += "H";
} else if (sign === "..") {
output += "I";
} else if (sign === ".---") {
output += "J";
} else if (sign === "-.-") {
output += "K";
} else if (sign === ".-..") {
output += "L";
} else if (sign === "--") {
output += "M";
} else if (sign === "-.") {
output += "N";
} else if (sign === "---") {
output += "O";
} else if (sign === ".--.") {
output += "P";
} else if (sign === "--.-") {
output += "Q";
} else if (sign === ".-.") {
output += "R";
} else if (sign === "...") {
output += "S";
} else if (sign === "-") {
output += "T";
} else if (sign === "..-") {
output += "U";
} else if (sign === "...-") {
output += "V";
} else if (sign === ".--") {
output += "W";
} else if (sign === "-..-") {
output += "X";
} else if (sign === "-.--") {
output += "Y";
} else if (sign === "--..") {
output += "Z";
} else if (sign === "-----") {
output += "0";
} else if (sign === ".----") {
output += "1";
} else if (sign === "..---") {
output += "2";
} else if (sign === "...--") {
output += "3";
} else if (sign === "....-") {
output += "4";
} else if (sign === ".....") {
output += "5";
} else if (sign === "-....") {
output += "6";
} else if (sign === "--...") {
output += "7";
} else if (sign === "---..") {
output += "8";
} else if (sign === "----.") {
output += "9";
} else if (sign === ".-.-") {
output += "Ä";
} else if (sign === "---.") {
output += "Ö";
} else if (sign === "..--") {
output += "Ü";
} else if (sign === "...--...") {
output += "ß";
} else if (sign === "----") {
output += "CH";
} else if (sign === ".-.-.-") {
output += ".";
} else if (sign === "--..--") {
output += ",";
} else if (sign === "---...") {
output += ":";
} else if (sign === "-.-.-.") {
output += ";";
} else if (sign === "..--..") {
output += "?";
} else if (sign === "-.-.--") {
output += "!";
} else if (sign === "-....-") {
output += "-";
} else if (sign === "..--.-") {
output += "_";
} else if (sign === "-.--.") {
output += "(";
} else if (sign === "-.--.-") {
output += ")";
} else if (sign === ".----.") {
output += "'";
} else if (sign === "-...-") {
output += "=";
} else if (sign === ".-.-.") {
output += "+";
} else if (sign === "-..-.") {
output += "/";
} else if (sign === ".--.-.") {
output += "@";
} else if (sign === "-.-.-") {
output += "Begin of the signal";
} else if (sign === "-...-") {
output += "Wait";
} else if (sign === "...-.") {
output += "Understood";
} else if (sign === "...-.-") {
output += "End of work";
} else if (sign === "...---...") {
output += "SOS";
} else if (sign === "........") {
output += "Error";
} else {
return "Code not listed or wrong.";
}
}
return output;
};

View file

@ -0,0 +1,523 @@
getWrittenMorseDecoded = (input) ->
# Well, this shouldn't happen...
if !(input)
return null
# remove trailing whitspaces
if input.charAt input.length is " "
input.substring 0, input.length - 1
input = input.toUpperCase()
output = ""
# Return special signs
if input is "LETTERSPACE"
return "#"
else if input is "END OF WORK"
return "000101"
else if input is "ERROR"
return "00000000"
else if input is "STARTING SIGNAL"
return "10101"
else if input is "ENDING SIGNAL"
return "01010"
else if input is "UNDERSTOOD"
return "00010"
else if input is "WAIT"
return "01000"
else if input is "SOS"
return "000111000"
else if input is "LETTER SPACE"
return "#"
else if input is "WORD SPACE"
return "+"
else # the converting part
while input.length > 0
if input.charAt(0) is " "
if output.charAt(output.length) is "#"
output = output.substring 0, output.length - 1
output += "+"
input = input.substring 1
else if input.charAt(0) is "\n"
output += "<br>"
input = input.substring 1
else if input.charAt(0) is "A"
output += "01#"
input = input.substring 1
else if input.charAt(0) is "B"
output += "1000#"
input = input.substring 1
else if input.charAt(0) is "C"
output += "1010#"
input = input.substring 1
else if input.charAt(0) is "D"
output += "100#"
input = input.substring 1
else if input.charAt(0) is "E"
output += "0#"
input = input.substring 1
else if input.charAt(0) is "F"
output += "0010#"
input = input.substring 1
else if input.charAt(0) is "G"
output += "110#"
input = input.substring 1
else if input.charAt(0) is "H"
output += "0000#"
input = input.substring 1
else if input.charAt(0) is "I"
output += "00#"
input = input.substring 1
else if input.charAt(0) is "J"
output += "0111#"
input = input.substring 1
else if input.charAt(0) is "K"
output += "101#"
input = input.substring 1
else if input.charAt(0) is "L"
output += "0100#"
input = input.substring 1
else if input.charAt(0) is "M"
output += "11#"
input = input.substring 1
else if input.charAt(0) is "N"
output += "10#"
input = input.substring 1
else if input.charAt(0) is "O"
output += "111#"
input = input.substring 1
else if input.charAt(0) is "P"
output += "0110#"
input = input.substring 1
else if input.charAt(0) is "Q"
output += "1101#"
input = input.substring 1
else if input.charAt(0) is "R"
output += "010#"
input = input.substring 1
else if input.charAt(0) is "S"
output += "000#"
input = input.substring 1
else if input.charAt(0) is "T"
output += "1#"
input = input.substring 1
else if input.charAt(0) is "U"
output += "001#"
input = input.substring 1
else if input.charAt(0) is "V"
output += "0001#"
input = input.substring 1
else if input.charAt(0) is "W"
output += "011#"
input = input.substring 1
else if input.charAt(0) is "X"
output += "1001#"
input = input.substring 1
else if input.charAt(0) is "Y"
output += "1011#"
input = input.substring 1
else if input.charAt(0) is "Z"
output += "1100#"
input = input.substring 1
else if input.charAt(0) is "0"
output += "11111#"
input = input.substring 1
else if input.charAt(0) is "1"
output += "01111#"
input = input.substring 1
else if input.charAt(0) is "2"
output += "00111#"
input = input.substring 1
else if input.charAt(0) is "3"
output += "00011#"
input = input.substring 1
else if input.charAt(0) is "4"
output += "00001#"
input = input.substring 1
else if input.charAt(0) is "5"
output += "00000#"
input = input.substring 1
else if input.charAt(0) is "6"
output += "10000#"
input = input.substring 1
else if input.charAt(0) is "7"
output += "11000#"
input = input.substring 1
else if input.charAt(0) is "8"
output += "11100#"
input = input.substring 1
else if input.charAt(0) is "9"
output += "11110#"
input = input.substring 1
else if input.charAt(0) is "Ä"
output += "0101#"
input = input.substring 1
else if input.charAt(0) is "Ö"
output += "1110#"
input = input.substring 1
else if input.charAt(0) is "Ü"
output += "0011#"
input = input.substring 1
else if input.charAt(0) is "ß"
output += "00011000#"
input = input.substring 1
else if input.charAt(0) is "."
output += "010101#"
input = input.substring 1
else if input.charAt(0) is ","
output += "110011#"
input = input.substring 1
else if input.charAt(0) is ":"
output += "111000#"
input = input.substring 1
else if input.charAt(0) is ""
output += "101010#"
input = input.substring 1
else if input.charAt(0) is "?"
output += "001100#"
input = input.substring 1
else if input.charAt(0) is "!"
output += "101011#"
input = input.substring 1
else if input.charAt(0) is "-"
output += "100001#"
input = input.substring 1
else if input.charAt(0) is "_"
output += "001101#"
input = input.substring 1
else if input.charAt(0) is "("
output += "10110#"
input = input.substring 1
else if input.charAt(0) is ")"
output += "101101#"
input = input.substring 1
else if input.charAt(0) is "="
output += "10001#"
input = input.substring 1
else if input.charAt(0) is "+"
output += "01010#"
input = input.substring 1
else if input.charAt(0) is "/"
output += "10010#"
input = input.substring 1
else if input.charAt(0) is "@"
output += "011010#"
input = input.substring 1
else if input.charAt(0) is "'"
output += "011110#"
input = input.substring 1
else if input.charAt(0) is "$"
output += "0001001#"
input = input.substring 1
else
return "Code not listed or wrong."
if output.charAt(output.length - 1) is "#"
output = output.substring 0, output.length - 1
return output
getWrittenMorseEncoded = (input) ->
# Well, this shouldn't happen...
if !(input) then return null
# remove trailing whitspaces
while input.charAt(input.length - 1) is " "
input = input.substring 0, input.length - 1
input = input.toUpperCase()
while input.charAt(input.length - 1) is "#" or
input.charAt(input.length - 1) is "+" or
input.charAt(input.length - 1) is "\n"
input = input.substring 0, input.length - 1
if input.charAt(input.length - 1) isnt "#"
input += "#"
inputToSign = input
output = ""
while inputToSign isnt "#"
d = 0
signFull = true
sign = ""
while signFull
if inputToSign.charAt(d) is "+" or
inputToSign.charAt(d) is "#" or
inputToSign.charAt(0) is "\n"
if d is 0
if inputToSign.charAt(0) is "+"
output += " "
inputToSign = inputToSign.substring 1, inputToSign.length
if inputToSign.charAt(0) is "#"
inputToSign = inputToSign.substring 1, inputToSign.length
if inputToSign.charAt(0) is "\n"
output += "<br>"
inputToSign = inputToSign.substring 1, inputToSign.length
else
sign = inputToSign.substring 0, d
inputToSign = inputToSign.substring d, inputToSign.length
signFull = false
else
d++
if sign is "01"
output += "A"
else if sign is "1000"
output += "B"
else if sign is "1010"
output += "C"
else if sign is "100"
output += "D"
else if sign is "0"
output += "E"
else if sign is "0010"
output += "F"
else if sign is "110"
output += "G"
else if sign is "0000"
output += "H"
else if sign is "00"
output += "I"
else if sign is "0111"
output += "J"
else if sign is "101"
output += "K"
else if sign is "0100"
output += "L"
else if sign is "11"
output += "M"
else if sign is "10"
output += "N"
else if sign is "111"
output += "O"
else if sign is "0110"
output += "P"
else if sign is "1101"
output += "Q"
else if sign is "010"
output += "R"
else if sign is "000"
output += "S"
else if sign is "1"
output += "T"
else if sign is "001"
output += "U"
else if sign is "0001"
output += "V"
else if sign is "011"
output += "W"
else if sign is "1001"
output += "X"
else if sign is "1011"
output += "Y"
else if sign is "1100"
output += "Z"
else if sign is "11111"
output += "0"
else if sign is "01111"
output += "1"
else if sign is "00111"
output += "2"
else if sign is "00011"
output += "3"
else if sign is "00001"
output += "4"
else if sign is "00000"
output += "5"
else if sign is "10000"
output += "6"
else if sign is "11000"
output += "7"
else if sign is "11100"
output += "8"
else if sign is "11110"
output += "9"
else if sign is "0101"
output += "Ä"
else if sign is "1110"
output += "Ö"
else if sign is "0011"
output += "Ü"
else if sign is "00011000"
output += "ß"
else if sign is "1111"
output += "CH"
else if sign is "010101"
output += "."
else if sign is "110011"
output += ","
else if sign is "111000"
output += ":"
else if sign is "101010"
output += ";"
else if sign is "001100"
output += "?"
else if sign is "101011"
output += "!"
else if sign is "100001"
output += "-"
else if sign is "001101"
output += "_"
else if sign is "10110"
output += "("
else if sign is "101101"
output += ")"
else if sign is "011110"
output += "'"
else if sign is "10001"
output += "="
else if sign is "01010"
output += "+"
else if sign is "10010"
output += "/"
else if sign is "011010"
output += "@"
else if sign is "10101"
output += "Begin of the signal"
else if sign is "10001"
output += "Wait"
else if sign is "00010"
output += "Understood"
else if sign is "000101"
output += "End of work"
else if sign is "000111000"
output += "SOS"
else if sign is "00000000"
output += "Error"
else
return "Code not listed or wrong."
return output

View file

@ -0,0 +1,396 @@
var getWrittenMorseDecoded, getWrittenMorseEncoded;
getWrittenMorseDecoded = function(input) {
var output;
if (!input) {
return null;
}
if (input.charAt(input.length === " ")) {
input.substring(0, input.length - 1);
}
input = input.toUpperCase();
output = "";
if (input === "LETTERSPACE") {
return "#";
} else if (input === "END OF WORK") {
return "000101";
} else if (input === "ERROR") {
return "00000000";
} else if (input === "STARTING SIGNAL") {
return "10101";
} else if (input === "ENDING SIGNAL") {
return "01010";
} else if (input === "UNDERSTOOD") {
return "00010";
} else if (input === "WAIT") {
return "01000";
} else if (input === "SOS") {
return "000111000";
} else if (input === "LETTER SPACE") {
return "#";
} else if (input === "WORD SPACE") {
return "+";
} else {
while (input.length > 0) {
if (input.charAt(0) === " ") {
if (output.charAt(output.length) === "#") {
output = output.substring(0, output.length - 1);
}
output += "+";
input = input.substring(1);
} else if (input.charAt(0) === "\n") {
output += "<br>";
input = input.substring(1);
} else if (input.charAt(0) === "A") {
output += "01#";
input = input.substring(1);
} else if (input.charAt(0) === "B") {
output += "1000#";
input = input.substring(1);
} else if (input.charAt(0) === "C") {
output += "1010#";
input = input.substring(1);
} else if (input.charAt(0) === "D") {
output += "100#";
input = input.substring(1);
} else if (input.charAt(0) === "E") {
output += "0#";
input = input.substring(1);
} else if (input.charAt(0) === "F") {
output += "0010#";
input = input.substring(1);
} else if (input.charAt(0) === "G") {
output += "110#";
input = input.substring(1);
} else if (input.charAt(0) === "H") {
output += "0000#";
input = input.substring(1);
} else if (input.charAt(0) === "I") {
output += "00#";
input = input.substring(1);
} else if (input.charAt(0) === "J") {
output += "0111#";
input = input.substring(1);
} else if (input.charAt(0) === "K") {
output += "101#";
input = input.substring(1);
} else if (input.charAt(0) === "L") {
output += "0100#";
input = input.substring(1);
} else if (input.charAt(0) === "M") {
output += "11#";
input = input.substring(1);
} else if (input.charAt(0) === "N") {
output += "10#";
input = input.substring(1);
} else if (input.charAt(0) === "O") {
output += "111#";
input = input.substring(1);
} else if (input.charAt(0) === "P") {
output += "0110#";
input = input.substring(1);
} else if (input.charAt(0) === "Q") {
output += "1101#";
input = input.substring(1);
} else if (input.charAt(0) === "R") {
output += "010#";
input = input.substring(1);
} else if (input.charAt(0) === "S") {
output += "000#";
input = input.substring(1);
} else if (input.charAt(0) === "T") {
output += "1#";
input = input.substring(1);
} else if (input.charAt(0) === "U") {
output += "001#";
input = input.substring(1);
} else if (input.charAt(0) === "V") {
output += "0001#";
input = input.substring(1);
} else if (input.charAt(0) === "W") {
output += "011#";
input = input.substring(1);
} else if (input.charAt(0) === "X") {
output += "1001#";
input = input.substring(1);
} else if (input.charAt(0) === "Y") {
output += "1011#";
input = input.substring(1);
} else if (input.charAt(0) === "Z") {
output += "1100#";
input = input.substring(1);
} else if (input.charAt(0) === "0") {
output += "11111#";
input = input.substring(1);
} else if (input.charAt(0) === "1") {
output += "01111#";
input = input.substring(1);
} else if (input.charAt(0) === "2") {
output += "00111#";
input = input.substring(1);
} else if (input.charAt(0) === "3") {
output += "00011#";
input = input.substring(1);
} else if (input.charAt(0) === "4") {
output += "00001#";
input = input.substring(1);
} else if (input.charAt(0) === "5") {
output += "00000#";
input = input.substring(1);
} else if (input.charAt(0) === "6") {
output += "10000#";
input = input.substring(1);
} else if (input.charAt(0) === "7") {
output += "11000#";
input = input.substring(1);
} else if (input.charAt(0) === "8") {
output += "11100#";
input = input.substring(1);
} else if (input.charAt(0) === "9") {
output += "11110#";
input = input.substring(1);
} else if (input.charAt(0) === "Ä") {
output += "0101#";
input = input.substring(1);
} else if (input.charAt(0) === "Ö") {
output += "1110#";
input = input.substring(1);
} else if (input.charAt(0) === "Ü") {
output += "0011#";
input = input.substring(1);
} else if (input.charAt(0) === "ß") {
output += "00011000#";
input = input.substring(1);
} else if (input.charAt(0) === ".") {
output += "010101#";
input = input.substring(1);
} else if (input.charAt(0) === ",") {
output += "110011#";
input = input.substring(1);
} else if (input.charAt(0) === ":") {
output += "111000#";
input = input.substring(1);
} else if (input.charAt(0) === "") {
output += "101010#";
input = input.substring(1);
} else if (input.charAt(0) === "?") {
output += "001100#";
input = input.substring(1);
} else if (input.charAt(0) === "!") {
output += "101011#";
input = input.substring(1);
} else if (input.charAt(0) === "-") {
output += "100001#";
input = input.substring(1);
} else if (input.charAt(0) === "_") {
output += "001101#";
input = input.substring(1);
} else if (input.charAt(0) === "(") {
output += "10110#";
input = input.substring(1);
} else if (input.charAt(0) === ")") {
output += "101101#";
input = input.substring(1);
} else if (input.charAt(0) === "=") {
output += "10001#";
input = input.substring(1);
} else if (input.charAt(0) === "+") {
output += "01010#";
input = input.substring(1);
} else if (input.charAt(0) === "/") {
output += "10010#";
input = input.substring(1);
} else if (input.charAt(0) === "@") {
output += "011010#";
input = input.substring(1);
} else if (input.charAt(0) === "'") {
output += "011110#";
input = input.substring(1);
} else if (input.charAt(0) === "$") {
output += "0001001#";
input = input.substring(1);
} else {
return "Code not listed or wrong.";
}
}
if (output.charAt(output.length - 1) === "#") {
output = output.substring(0, output.length - 1);
}
}
return output;
};
getWrittenMorseEncoded = function(input) {
var d, inputToSign, output, sign, signFull;
if (!input) {
return null;
}
while (input.charAt(input.length - 1) === " ") {
input = input.substring(0, input.length - 1);
}
input = input.toUpperCase();
while (input.charAt(input.length - 1) === "#" || input.charAt(input.length - 1) === "+" || input.charAt(input.length - 1) === "\n") {
input = input.substring(0, input.length - 1);
}
if (input.charAt(input.length - 1) !== "#") {
input += "#";
}
inputToSign = input;
output = "";
while (inputToSign !== "#") {
d = 0;
signFull = true;
sign = "";
while (signFull) {
if (inputToSign.charAt(d) === "+" || inputToSign.charAt(d) === "#" || inputToSign.charAt(0) === "\n") {
if (d === 0) {
if (inputToSign.charAt(0) === "+") {
output += " ";
inputToSign = inputToSign.substring(1, inputToSign.length);
}
if (inputToSign.charAt(0) === "#") {
inputToSign = inputToSign.substring(1, inputToSign.length);
}
if (inputToSign.charAt(0) === "\n") {
output += "<br>";
inputToSign = inputToSign.substring(1, inputToSign.length);
}
} else {
sign = inputToSign.substring(0, d);
inputToSign = inputToSign.substring(d, inputToSign.length);
signFull = false;
}
} else {
d++;
}
}
if (sign === "01") {
output += "A";
} else if (sign === "1000") {
output += "B";
} else if (sign === "1010") {
output += "C";
} else if (sign === "100") {
output += "D";
} else if (sign === "0") {
output += "E";
} else if (sign === "0010") {
output += "F";
} else if (sign === "110") {
output += "G";
} else if (sign === "0000") {
output += "H";
} else if (sign === "00") {
output += "I";
} else if (sign === "0111") {
output += "J";
} else if (sign === "101") {
output += "K";
} else if (sign === "0100") {
output += "L";
} else if (sign === "11") {
output += "M";
} else if (sign === "10") {
output += "N";
} else if (sign === "111") {
output += "O";
} else if (sign === "0110") {
output += "P";
} else if (sign === "1101") {
output += "Q";
} else if (sign === "010") {
output += "R";
} else if (sign === "000") {
output += "S";
} else if (sign === "1") {
output += "T";
} else if (sign === "001") {
output += "U";
} else if (sign === "0001") {
output += "V";
} else if (sign === "011") {
output += "W";
} else if (sign === "1001") {
output += "X";
} else if (sign === "1011") {
output += "Y";
} else if (sign === "1100") {
output += "Z";
} else if (sign === "11111") {
output += "0";
} else if (sign === "01111") {
output += "1";
} else if (sign === "00111") {
output += "2";
} else if (sign === "00011") {
output += "3";
} else if (sign === "00001") {
output += "4";
} else if (sign === "00000") {
output += "5";
} else if (sign === "10000") {
output += "6";
} else if (sign === "11000") {
output += "7";
} else if (sign === "11100") {
output += "8";
} else if (sign === "11110") {
output += "9";
} else if (sign === "0101") {
output += "Ä";
} else if (sign === "1110") {
output += "Ö";
} else if (sign === "0011") {
output += "Ü";
} else if (sign === "00011000") {
output += "ß";
} else if (sign === "1111") {
output += "CH";
} else if (sign === "010101") {
output += ".";
} else if (sign === "110011") {
output += ",";
} else if (sign === "111000") {
output += ":";
} else if (sign === "101010") {
output += ";";
} else if (sign === "001100") {
output += "?";
} else if (sign === "101011") {
output += "!";
} else if (sign === "100001") {
output += "-";
} else if (sign === "001101") {
output += "_";
} else if (sign === "10110") {
output += "(";
} else if (sign === "101101") {
output += ")";
} else if (sign === "011110") {
output += "'";
} else if (sign === "10001") {
output += "=";
} else if (sign === "01010") {
output += "+";
} else if (sign === "10010") {
output += "/";
} else if (sign === "011010") {
output += "@";
} else if (sign === "10101") {
output += "Begin of the signal";
} else if (sign === "10001") {
output += "Wait";
} else if (sign === "00010") {
output += "Understood";
} else if (sign === "000101") {
output += "End of work";
} else if (sign === "000111000") {
output += "SOS";
} else if (sign === "00000000") {
output += "Error";
} else {
return "Code not listed or wrong.";
}
}
return output;
};