From 497a087270e527da56e403a4f53441f7b9ada8c6 Mon Sep 17 00:00:00 2001 From: "Marcel Kapfer (mmk2410)" Date: Mon, 30 May 2016 23:16:30 +0200 Subject: [PATCH] Switch from CoffeeScript to Dart with convert engine --- .gitignore | 10 + README.md | 10 +- app/index.html | 4 +- app/scripts/CodeRecognization.coffee | 59 --- app/scripts/CodeRecognization.dart | 60 +++ app/scripts/CodeRecognization.js | 11 - app/scripts/Convert.dart | 217 ++++++++++ app/scripts/MorseConverter.dart | 39 ++ app/scripts/app.js | 10 +- app/scripts/normalMorseConvert.coffee | 522 ------------------------ app/scripts/normalMorseConvert.js | 394 ------------------- app/scripts/writtenMorseConvert.coffee | 523 ------------------------- app/scripts/writtenMorseConvert.js | 396 ------------------- 13 files changed, 340 insertions(+), 1915 deletions(-) delete mode 100644 app/scripts/CodeRecognization.coffee create mode 100644 app/scripts/CodeRecognization.dart delete mode 100644 app/scripts/CodeRecognization.js create mode 100644 app/scripts/Convert.dart create mode 100644 app/scripts/MorseConverter.dart delete mode 100644 app/scripts/normalMorseConvert.coffee delete mode 100644 app/scripts/normalMorseConvert.js delete mode 100644 app/scripts/writtenMorseConvert.coffee delete mode 100644 app/scripts/writtenMorseConvert.js diff --git a/.gitignore b/.gitignore index 3fc21ca..1d8df96 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,13 @@ test/temp bower_components .tmp test/bower_components/ + +# Dart files +pubspec.lock +packages/ +.pub/ +.packages +app/scripts/MorseConverter.js* + +# Atom editor +.atom/ diff --git a/README.md b/README.md index c8dd873..1f13aa8 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ The webapp can be accessed at [marcel-kapfer.de/writtenmorse/morseconverter](htt You need the following programs installed on your computer: ``` -npm, bower, gulp +npm, bower, gulp, dart2js ``` To see your changes run the first time: @@ -30,7 +30,13 @@ To see your changes run the first time: npm install && bower install ``` -and the rebuild the webapp with: +Now change to `app/scripts/` and compile the `MorseConverter.dart`: + +``` +dart2js -m MorseConverter.dart -o MorseConverter.js +``` + +and then rebuild the webapp with: ``` gulp diff --git a/app/index.html b/app/index.html index 5c4aefa..75cf20b 100644 --- a/app/index.html +++ b/app/index.html @@ -117,9 +117,7 @@ - - - + diff --git a/app/scripts/CodeRecognization.coffee b/app/scripts/CodeRecognization.coffee deleted file mode 100644 index 8db5129..0000000 --- a/app/scripts/CodeRecognization.coffee +++ /dev/null @@ -1,59 +0,0 @@ -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) diff --git a/app/scripts/CodeRecognization.dart b/app/scripts/CodeRecognization.dart new file mode 100644 index 0000000..5543722 --- /dev/null +++ b/app/scripts/CodeRecognization.dart @@ -0,0 +1,60 @@ +/** + * 2016 (c) Marcel Kapfer (mmk2410) + * Licensed under MIT License + */ + +import 'Convert.dart'; + +/** + * Detect code. + */ +class CodeRecognization { + + /** + * Detect if message is Morse code. + * + * @param message string to be checked. + * @return Boolean true if message is Morse code. + */ + static bool isMorseCode(String message) { + + List alphabet = new List.from(Convert.alphabet); + alphabet = alphabet + ..remove('.') + ..remove('-') + ..remove(' '); + + for (String char in message.toUpperCase().split('')) { + if (alphabet.contains(char)) { + return false; + } + } + + return true; + } + + /** + * Detect if message is writtenMorse code. + * + * @param message string to be checked. + * @return Boolean true if message is writtenMorse coe. + */ + static bool isWrittenMorseCode(String message) { + + List alphabet = new List.from(Convert.alphabet); + alphabet = alphabet + ..remove('0') + ..remove('1') + ..remove('#') + ..remove('+'); + + for (String char in message.toUpperCase().split('')) { + if (alphabet.contains(char)) { + return false; + } + } + + return true; + } + +} diff --git a/app/scripts/CodeRecognization.js b/app/scripts/CodeRecognization.js deleted file mode 100644 index d634cd5..0000000 --- a/app/scripts/CodeRecognization.js +++ /dev/null @@ -1,11 +0,0 @@ -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); -}; diff --git a/app/scripts/Convert.dart b/app/scripts/Convert.dart new file mode 100644 index 0000000..2273e62 --- /dev/null +++ b/app/scripts/Convert.dart @@ -0,0 +1,217 @@ +/** + * 2016 (c) Marcel Kapfer (mmk2410) + * Licensed under MIT License + */ + +/** + * Methods for converting Morse and writtenMorse code. + */ +class Convert { + + // Normal alphabet. + static List alphabet = [ + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', + 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', + 'U', 'V', 'W', 'X', 'Y', 'Z', '0', '1', '2', '3', + '4', '5', '6', '7', '8', '9', 'Ä', 'Ö', 'Ü', 'ß', + '.', ',', ':', ';', '?', '!', '-', '_', '(', ')', + '=', '+', '/', '@', "'", '\$', '\n', " ", '
' + ]; + + // Normal alphabet signal words. + static List alphabetExtra = [ + 'LETTERSPACE', 'END OF WORK', 'ERROR', 'STARTING SIGNAL', 'ENDING SIGNAL', + 'UNDERSTOOD', 'WAIT', 'SOS', 'LETTER SPACE', 'WORD SPACE' + ]; + + // writtenMorse Alphabet. + static List writtenMorse = [ + '01', '1000', '1010', '100', '0', '0010', + '110', '0000', '00', '0111', '101', '0100', + '11', '10', '111', '0110', '1101', '010', + '000', '1', '001', '0001', '011', '1001', + '1011', '1100', '11111', '01111', '00111', + '00011', '00001', '00000', '10000', '11000', + '11100', '11110', '0101', '1110', '0011', + '00011000', '010101', '110011', '111000', + '101010', '001100', '101011', '100001', '001101', + '10110', '101101', '10001', '01010', '10010', + '011010', '011110', '0001001', '
', "+", '\n' + ]; + + // writtenMorse alphabet signal words. + static List writtenMorseExtra = [ + '#', '000101', '00000000', '10101', '01010', '00010', '01000', + '000111000', '#', '+' + ]; + + // writtenMorse separators. + static List writtenMorseSeparators = ['#', '+']; + + // Morse alphabet. + static List morse = [ + '.-', '-...', '-.-.', '-..', '.', '..-.', '--.', '....', '..', '.---', + '-.-', '.-..', '--', '-.', '---', '.--.', '--.-', '.-.', '...', '-', '..-', + '...-', '.--', '-..-', '-.--', '--..', '-----', '.----', '..---', '...--', + '....-', '.....', '-....', '--...', '---..', '----.', '.-.-', '---.', '..--', + '...--...', '.-.-.-', '--..--', '---...', '-.-.-.', '..--..', '-.-.--', + '-....-', '..--.-', '-.--.', '-.--.-', '-...-', '.-.-.', '-..-.', '.--.-.', + '.----.', '...-..-', '
', ' ', '\n' + ]; + + // Morse alphabet signal words. + static List morseExtra = [ + ' ', '...-.-', '........', '-.-.-', '.-.-.', '...-.', '.-...', + '...---...', ' ', ' ' + ]; + + // Morse separators. + static List morseSeparators = [' ', ' ']; + + /** + * Convert message to writtenMorse code. + * + * @param message Message to convert. + * @return converted message. + */ + static String getWrittenMorseEncoded(String message) { + return _encode( + message, writtenMorse, writtenMorseExtra, writtenMorseSeparators); + } + + /** + * Convert messgae from writtenMorse code. + * + * @param message Message to convert. + * @return converted Message. + */ + static String getWrittenMorseDecoded(String message) { + return _decode( + message, writtenMorse, writtenMorseExtra, writtenMorseSeparators); + } + + /** + * Convert messgae to Morse code. + * + * @param message Message to convert. + * @return converted Message. + */ + static String getMorseEncoded(String message) { + return _encode( + message, morse, morseExtra, morseSeparators).replaceAll(" ", " "); + } + + /** + * Convert messgae from Morse code. + * + * @param message Message to convert. + * @return converted Message. + */ + static String getMorseDecoded(String message) { + return _decode( + message, morse, morseExtra, morseSeparators); + } + + /** + * Convert message to given alphabet. + * + * @param message Message to convert. + * @param codeAlphabet Alphabet of the code to convert to. + * @param codeAlphabetExtra Signal words of code to convert to. + * @param separators Separators of code to convert to. + * @return Converted message. + */ + static String _encode(String message, List codeAlphabet, List codeAlphabetExtra, List separators) { + + message = message.trim().toUpperCase(); + + if (message.isEmpty) { + return null; + } + + if (alphabetExtra.contains(message)) { + return codeAlphabetExtra[alphabetExtra.indexOf(message)]; + } + + StringBuffer converted = new StringBuffer(); + + List messageList = message.split(''); + + for (int i = 0; i < messageList.length; i++) { + String char = messageList[i]; + + converted.write( + codeAlphabet[alphabet.indexOf(char)] + ); + + if ((i < messageList.length - 1) + && (char != " ") + && (messageList[i + 1] != " ") + ) { + converted.write(separators[0]); + } + } + + return converted.toString().substring(0, converted.length); + + } + + /** + * Convert message from given alphabet. + * + * @param message Message to convert. + * @param codeAlphabet Alphabet of the code to convert from. + * @param codeAlphabetExtra Signal words of code to convert from. + * @param separators Separators of code to convert from. + * @return Converted message. + */ + static String _decode(String message, List codeAlphabet, List codeAlphabetExtra, List separators) { + + message = message.trim().toUpperCase(); + + if(message.isEmpty) { + return null; + } + + if(codeAlphabetExtra.contains(message)) { + return alphabetExtra[codeAlphabetExtra.indexOf(message)]; + } + + StringBuffer converted = new StringBuffer(); + + List lineList = message.split("\n"); + + for (String line in lineList) { + + List wordList = line.split(separators[1]); + + for(int i = 0; i < wordList.length; i++) { + String word = wordList[i]; + + List charList = word.split(separators[0]); + + for(String char in charList) { + + if (codeAlphabet.contains(char)) { + converted.write( + alphabet[codeAlphabet.indexOf(char)] + ); + } + + } + + if (i < wordList.length - 1) { + converted.write(" "); + } + + } + + converted.write("\n"); + + } + + return converted.toString().substring(0, converted.length - 1); + + } + +} diff --git a/app/scripts/MorseConverter.dart b/app/scripts/MorseConverter.dart new file mode 100644 index 0000000..774e80d --- /dev/null +++ b/app/scripts/MorseConverter.dart @@ -0,0 +1,39 @@ +/** + * 2016 (c) Marcel Kapfer (mmk2410) + * Licensed under MIT License + */ + +/** + * JS interopt file for making the Dart methods accessible in JavaScript. + */ + +import 'dart:js' as js; + +import 'Convert.dart'; +import 'CodeRecognization.dart'; + +void main() { + js.context['isMorseCode'] = (message) { + return CodeRecognization.isMorseCode(message); + }; + + js.context['isWrittenMorseCode'] = (message) { + return CodeRecognization.isWrittenMorseCode(message); + }; + + js.context['getWrittenMorseEncoded'] = (message) { + return Convert.getWrittenMorseEncoded(message); + }; + + js.context['getWrittenMorseDecoded'] = (message) { + return Convert.getWrittenMorseDecoded(message); + }; + + js.context['getMorseEncoded'] = (message) { + return Convert.getMorseEncoded(message); + }; + + js.context['getMorseDecoded'] = (message) { + return Convert.getMorseDecoded(message); + }; +} diff --git a/app/scripts/app.js b/app/scripts/app.js index 2a9c9c9..cd0dbdf 100644 --- a/app/scripts/app.js +++ b/app/scripts/app.js @@ -71,15 +71,15 @@ } if (writtenMorse) { if (isWrittenMorseCode(input.value)) { - string = getWrittenMorseEncoded(input.value); - } else { string = getWrittenMorseDecoded(input.value); + } else { + string = getWrittenMorseEncoded(input.value); } } else { - if (isNormalMorseCode(input.value)) { - string = getNormalMorseEncoded(input.value); + if (isMorseCode(input.value)) { + string = getMorseDecoded(input.value); } else { - string = getNormalMorseDecoded(input.value); + string = getMorseEncoded(input.value); } } outputArea.innerHTML = string; diff --git a/app/scripts/normalMorseConvert.coffee b/app/scripts/normalMorseConvert.coffee deleted file mode 100644 index a7e41d6..0000000 --- a/app/scripts/normalMorseConvert.coffee +++ /dev/null @@ -1,522 +0,0 @@ -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 "   " - 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 "   " - 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 += "
" - input = input.substring 1 - - else if input.charAt(0) is "A" - output += ".-   " - input = input.substring 1 - - else if input.charAt(0) is "B" - output += "-...   " - input = input.substring 1 - - else if input.charAt(0) is "C" - output += "-.-.   " - input = input.substring 1 - - else if input.charAt(0) is "D" - output += "-..   " - input = input.substring 1 - - else if input.charAt(0) is "E" - output += ".   " - input = input.substring 1 - - else if input.charAt(0) is "F" - output += "..-.   " - input = input.substring 1 - - else if input.charAt(0) is "G" - output += "--.   " - input = input.substring 1 - - else if input.charAt(0) is "H" - output += "....   " - input = input.substring 1 - - else if input.charAt(0) is "I" - output += "..   " - input = input.substring 1 - - else if input.charAt(0) is "J" - output += ".---   " - input = input.substring 1 - - else if input.charAt(0) is "K" - output += "-.-   " - input = input.substring 1 - - else if input.charAt(0) is "L" - output += ".-..   " - input = input.substring 1 - - else if input.charAt(0) is "M" - output += "--   " - input = input.substring 1 - - else if input.charAt(0) is "N" - output += "-.   " - input = input.substring 1 - - else if input.charAt(0) is "O" - output += "---   " - input = input.substring 1 - - else if input.charAt(0) is "P" - output += ".--.   " - input = input.substring 1 - - else if input.charAt(0) is "Q" - output += "--.-   " - input = input.substring 1 - - else if input.charAt(0) is "R" - output += ".-.   " - input = input.substring 1 - - else if input.charAt(0) is "S" - output += "...   " - input = input.substring 1 - - else if input.charAt(0) is "T" - output += "-   " - input = input.substring 1 - - else if input.charAt(0) is "U" - output += "..-   " - input = input.substring 1 - - else if input.charAt(0) is "V" - output += "...-   " - input = input.substring 1 - - else if input.charAt(0) is "W" - output += ".--   " - input = input.substring 1 - - else if input.charAt(0) is "X" - output += "-..-   " - input = input.substring 1 - - else if input.charAt(0) is "Y" - output += "-.--   " - input = input.substring 1 - - else if input.charAt(0) is "Z" - output += "--..   " - input = input.substring 1 - - else if input.charAt(0) is "0" - output += "-----   " - input = input.substring 1 - - else if input.charAt(0) is "1" - output += ".----   " - input = input.substring 1 - - else if input.charAt(0) is "2" - output += "..---   " - input = input.substring 1 - - else if input.charAt(0) is "3" - output += "...--   " - input = input.substring 1 - - else if input.charAt(0) is "4" - output += "....-   " - input = input.substring 1 - - else if input.charAt(0) is "5" - output += ".....   " - input = input.substring 1 - - else if input.charAt(0) is "6" - output += "-....   " - input = input.substring 1 - - else if input.charAt(0) is "7" - output += "--...   " - input = input.substring 1 - - else if input.charAt(0) is "8" - output += "---..   " - input = input.substring 1 - - else if input.charAt(0) is "9" - output += "----.   " - input = input.substring 1 - - else if input.charAt(0) is "Ä" - output += ".-.-   " - input = input.substring 1 - - else if input.charAt(0) is "Ö" - output += "---.   " - input = input.substring 1 - - else if input.charAt(0) is "Ü" - output += "..--   " - input = input.substring 1 - - else if input.charAt(0) is "ß" - output += "...--...   " - input = input.substring 1 - - else if input.charAt(0) is "." - output += ".-.-.-   " - input = input.substring 1 - - else if input.charAt(0) is "," - output += "--..--   " - input = input.substring 1 - - else if input.charAt(0) is ":" - output += "---...   " - input = input.substring 1 - - else if input.charAt(0) is "" - output += "-.-.-.   " - input = input.substring 1 - - else if input.charAt(0) is "?" - output += "..--..   " - input = input.substring 1 - - else if input.charAt(0) is "!" - output += "-.-.--   " - input = input.substring 1 - - else if input.charAt(0) is "-" - output += "-....-   " - input = input.substring 1 - - else if input.charAt(0) is "_" - output += "..--.-   " - input = input.substring 1 - - else if input.charAt(0) is "(" - output += "-.--.   " - input = input.substring 1 - - else if input.charAt(0) is ")" - output += "-.--.-   " - input = input.substring 1 - - else if input.charAt(0) is "=" - output += "-...-   " - input = input.substring 1 - - else if input.charAt(0) is "+" - output += ".-.-.   " - input = input.substring 1 - - else if input.charAt(0) is "/" - output += "-..-.   " - input = input.substring 1 - - else if input.charAt(0) is "@" - output += ".--.-.   " - input = input.substring 1 - - else if input.charAt(0) is "'" - output += ".----.   " - input = input.substring 1 - - else if input.charAt(0) is "$" - output += "...-..-   " - 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 += "
" - 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 diff --git a/app/scripts/normalMorseConvert.js b/app/scripts/normalMorseConvert.js deleted file mode 100644 index 8175e6e..0000000 --- a/app/scripts/normalMorseConvert.js +++ /dev/null @@ -1,394 +0,0 @@ -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 "   "; - } 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 "   "; - } 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 += "
"; - input = input.substring(1); - } else if (input.charAt(0) === "A") { - output += ".-   "; - input = input.substring(1); - } else if (input.charAt(0) === "B") { - output += "-...   "; - input = input.substring(1); - } else if (input.charAt(0) === "C") { - output += "-.-.   "; - input = input.substring(1); - } else if (input.charAt(0) === "D") { - output += "-..   "; - input = input.substring(1); - } else if (input.charAt(0) === "E") { - output += ".   "; - input = input.substring(1); - } else if (input.charAt(0) === "F") { - output += "..-.   "; - input = input.substring(1); - } else if (input.charAt(0) === "G") { - output += "--.   "; - input = input.substring(1); - } else if (input.charAt(0) === "H") { - output += "....   "; - input = input.substring(1); - } else if (input.charAt(0) === "I") { - output += "..   "; - input = input.substring(1); - } else if (input.charAt(0) === "J") { - output += ".---   "; - input = input.substring(1); - } else if (input.charAt(0) === "K") { - output += "-.-   "; - input = input.substring(1); - } else if (input.charAt(0) === "L") { - output += ".-..   "; - input = input.substring(1); - } else if (input.charAt(0) === "M") { - output += "--   "; - input = input.substring(1); - } else if (input.charAt(0) === "N") { - output += "-.   "; - input = input.substring(1); - } else if (input.charAt(0) === "O") { - output += "---   "; - input = input.substring(1); - } else if (input.charAt(0) === "P") { - output += ".--.   "; - input = input.substring(1); - } else if (input.charAt(0) === "Q") { - output += "--.-   "; - input = input.substring(1); - } else if (input.charAt(0) === "R") { - output += ".-.   "; - input = input.substring(1); - } else if (input.charAt(0) === "S") { - output += "...   "; - input = input.substring(1); - } else if (input.charAt(0) === "T") { - output += "-   "; - input = input.substring(1); - } else if (input.charAt(0) === "U") { - output += "..-   "; - input = input.substring(1); - } else if (input.charAt(0) === "V") { - output += "...-   "; - input = input.substring(1); - } else if (input.charAt(0) === "W") { - output += ".--   "; - input = input.substring(1); - } else if (input.charAt(0) === "X") { - output += "-..-   "; - input = input.substring(1); - } else if (input.charAt(0) === "Y") { - output += "-.--   "; - input = input.substring(1); - } else if (input.charAt(0) === "Z") { - output += "--..   "; - input = input.substring(1); - } else if (input.charAt(0) === "0") { - output += "-----   "; - input = input.substring(1); - } else if (input.charAt(0) === "1") { - output += ".----   "; - input = input.substring(1); - } else if (input.charAt(0) === "2") { - output += "..---   "; - input = input.substring(1); - } else if (input.charAt(0) === "3") { - output += "...--   "; - input = input.substring(1); - } else if (input.charAt(0) === "4") { - output += "....-   "; - input = input.substring(1); - } else if (input.charAt(0) === "5") { - output += ".....   "; - input = input.substring(1); - } else if (input.charAt(0) === "6") { - output += "-....   "; - input = input.substring(1); - } else if (input.charAt(0) === "7") { - output += "--...   "; - input = input.substring(1); - } else if (input.charAt(0) === "8") { - output += "---..   "; - input = input.substring(1); - } else if (input.charAt(0) === "9") { - output += "----.   "; - input = input.substring(1); - } else if (input.charAt(0) === "Ä") { - output += ".-.-   "; - input = input.substring(1); - } else if (input.charAt(0) === "Ö") { - output += "---.   "; - input = input.substring(1); - } else if (input.charAt(0) === "Ü") { - output += "..--   "; - input = input.substring(1); - } else if (input.charAt(0) === "ß") { - output += "...--...   "; - input = input.substring(1); - } else if (input.charAt(0) === ".") { - output += ".-.-.-   "; - input = input.substring(1); - } else if (input.charAt(0) === ",") { - output += "--..--   "; - input = input.substring(1); - } else if (input.charAt(0) === ":") { - output += "---...   "; - input = input.substring(1); - } else if (input.charAt(0) === "") { - output += "-.-.-.   "; - input = input.substring(1); - } else if (input.charAt(0) === "?") { - output += "..--..   "; - input = input.substring(1); - } else if (input.charAt(0) === "!") { - output += "-.-.--   "; - input = input.substring(1); - } else if (input.charAt(0) === "-") { - output += "-....-   "; - input = input.substring(1); - } else if (input.charAt(0) === "_") { - output += "..--.-   "; - input = input.substring(1); - } else if (input.charAt(0) === "(") { - output += "-.--.   "; - input = input.substring(1); - } else if (input.charAt(0) === ")") { - output += "-.--.-   "; - input = input.substring(1); - } else if (input.charAt(0) === "=") { - output += "-...-   "; - input = input.substring(1); - } else if (input.charAt(0) === "+") { - output += ".-.-.   "; - input = input.substring(1); - } else if (input.charAt(0) === "/") { - output += "-..-.   "; - input = input.substring(1); - } else if (input.charAt(0) === "@") { - output += ".--.-.   "; - input = input.substring(1); - } else if (input.charAt(0) === "'") { - output += ".----.   "; - input = input.substring(1); - } else if (input.charAt(0) === "$") { - output += "...-..-   "; - 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 += "
"; - 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; -}; diff --git a/app/scripts/writtenMorseConvert.coffee b/app/scripts/writtenMorseConvert.coffee deleted file mode 100644 index 4c31555..0000000 --- a/app/scripts/writtenMorseConvert.coffee +++ /dev/null @@ -1,523 +0,0 @@ -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 += "
" - 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 += "
" - 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 diff --git a/app/scripts/writtenMorseConvert.js b/app/scripts/writtenMorseConvert.js deleted file mode 100644 index 9d5e9d8..0000000 --- a/app/scripts/writtenMorseConvert.js +++ /dev/null @@ -1,396 +0,0 @@ -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 += "
"; - 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 += "
"; - 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; -};