Added the normal morse encryption
This commit is contained in:
parent
0e78a407e5
commit
954f57f221
3 changed files with 222 additions and 1 deletions
|
@ -13,6 +13,7 @@
|
|||
<script src="js/web/web.js"></script>
|
||||
<script src="js/engine/EncryptWrittenMorse.js"></script>
|
||||
<script src="js/engine/DecryptWrittenMorse.js"></script>
|
||||
<script src="js/engine/EncryptNormalMorse.js"></script>
|
||||
<script src="js/engine/DecryptNormalMorse.js"></script>
|
||||
|
||||
</head>
|
||||
|
|
220
js/engine/EncryptNormalMorse.js
Normal file
220
js/engine/EncryptNormalMorse.js
Normal file
|
@ -0,0 +1,220 @@
|
|||
function encryptNormalMorseManager(message) {
|
||||
if(message == ""){
|
||||
return "Please enter at least one character"
|
||||
} else {
|
||||
if (message.endsWith(" ")) {
|
||||
message = message.substring(0, message.length - 3)
|
||||
}
|
||||
// Variables
|
||||
var input = message.toUpperCase()
|
||||
while(input.indexOf('\n') != -1){
|
||||
input = input.replace("\n","")
|
||||
}
|
||||
var output = ""
|
||||
if (input == "LETTERSPACE") {
|
||||
output = " "
|
||||
} else if (input == "END OF WORK") {
|
||||
output = "...-.-"
|
||||
} else if (input == "ERROR") {
|
||||
output = "........"
|
||||
} else if (input == "STARTING SIGNAL") {
|
||||
output = "-.-.-"
|
||||
} else if (input == "ENDING SIGNAL") {
|
||||
output = ".-.-."
|
||||
} else if (input == "UNDERSTOOD") {
|
||||
output = "...-."
|
||||
} else if (input == "WAIT") {
|
||||
output = ".-..."
|
||||
} else if (input == "SOS") {
|
||||
output = "...---..."
|
||||
} else if (input == "LETTER SPACE") {
|
||||
output = " "
|
||||
} else if (input == "WORD SPACE") {
|
||||
output = " "
|
||||
} else {
|
||||
for (var c = input.length; c > 0; c--) {
|
||||
if (input.startsWith(" ")) {
|
||||
if (output.endsWith(" ")) {
|
||||
output = output.substring(0, output.length - 3)
|
||||
}
|
||||
output = output + " "
|
||||
input = input.substring(1, input.length)
|
||||
} else if (input.startsWith("A")) {
|
||||
output = output + ".- "
|
||||
input = input.substring(1, input.length)
|
||||
} else if (input.startsWith("B")) {
|
||||
output = output +"-... "
|
||||
input = input.substring(1, input.length)
|
||||
} else if (input.startsWith("C")) {
|
||||
output = output +"-.-. "
|
||||
input = input.substring(1, input.length)
|
||||
} else if (input.startsWith("D")) {
|
||||
output = output +"-.. "
|
||||
input = input.substring(1, input.length)
|
||||
} else if (input.startsWith("E")) {
|
||||
output = output +". "
|
||||
input = input.substring(1, input.length)
|
||||
} else if (input.startsWith("F")) {
|
||||
output = output +"..-. "
|
||||
input = input.substring(1, input.length)
|
||||
} else if (input.startsWith("G")) {
|
||||
output = output +"--. "
|
||||
input = input.substring(1, input.length)
|
||||
} else if (input.startsWith("H")) {
|
||||
output = output +".... "
|
||||
input = input.substring(1, input.length)
|
||||
} else if (input.startsWith("I")) {
|
||||
output = output +".. "
|
||||
input = input.substring(1, input.length)
|
||||
} else if (input.startsWith("J")) {
|
||||
output = output +".--- "
|
||||
input = input.substring(1, input.length)
|
||||
} else if (input.startsWith("K")) {
|
||||
output = output +"-.- "
|
||||
input = input.substring(1, input.length)
|
||||
} else if (input.startsWith("L")) {
|
||||
output = output +".-.. "
|
||||
input = input.substring(1, input.length)
|
||||
} else if (input.startsWith("M")) {
|
||||
output = output +"-- "
|
||||
input = input.substring(1, input.length)
|
||||
} else if (input.startsWith("N")) {
|
||||
output = output +"-. "
|
||||
input = input.substring(1, input.length)
|
||||
} else if (input.startsWith("O")) {
|
||||
output = output +"--- "
|
||||
input = input.substring(1, input.length)
|
||||
} else if (input.startsWith("P")) {
|
||||
output = output +".--. "
|
||||
input = input.substring(1, input.length)
|
||||
} else if (input.startsWith("Q")) {
|
||||
output = output +"--.- "
|
||||
input = input.substring(1, input.length)
|
||||
} else if (input.startsWith("R")) {
|
||||
output = output +".-. "
|
||||
input = input.substring(1, input.length)
|
||||
} else if (input.startsWith("S")) {
|
||||
output = output +"... "
|
||||
input = input.substring(1, input.length)
|
||||
} else if (input.startsWith("T")) {
|
||||
output = output +"- "
|
||||
input = input.substring(1, input.length)
|
||||
} else if (input.startsWith("U")) {
|
||||
output = output +"..- "
|
||||
input = input.substring(1, input.length)
|
||||
} else if (input.startsWith("V")) {
|
||||
output = output +"...- "
|
||||
input = input.substring(1, input.length)
|
||||
} else if (input.startsWith("W")) {
|
||||
output = output +".-- "
|
||||
input = input.substring(1, input.length)
|
||||
} else if (input.startsWith("X")) {
|
||||
output = output +"-..- "
|
||||
input = input.substring(1, input.length)
|
||||
} else if (input.startsWith("Y")) {
|
||||
output = output +"-.-- "
|
||||
input = input.substring(1, input.length)
|
||||
} else if (input.startsWith("Z")) {
|
||||
output = output +"--.. "
|
||||
input = input.substring(1, input.length)
|
||||
} else if (input.startsWith("0")) {
|
||||
output = output +"----- "
|
||||
input = input.substring(1, input.length)
|
||||
} else if (input.startsWith("1")) {
|
||||
output = output +".---- "
|
||||
input = input.substring(1, input.length)
|
||||
} else if (input.startsWith("2")) {
|
||||
output = output +"..--- "
|
||||
input = input.substring(1, input.length)
|
||||
} else if (input.startsWith("3")) {
|
||||
output = output +"...-- "
|
||||
input = input.substring(1, input.length)
|
||||
} else if (input.startsWith("4")) {
|
||||
output = output +"....- "
|
||||
input = input.substring(1, input.length)
|
||||
} else if (input.startsWith("5")) {
|
||||
output = output +"..... "
|
||||
input = input.substring(1, input.length)
|
||||
} else if (input.startsWith("6")) {
|
||||
output = output +"-.... "
|
||||
input = input.substring(1, input.length)
|
||||
} else if (input.startsWith("7")) {
|
||||
output = output +"--... "
|
||||
input = input.substring(1, input.length)
|
||||
} else if (input.startsWith("8")) {
|
||||
output = output +"---.. "
|
||||
input = input.substring(1, input.length)
|
||||
} else if (input.startsWith("9")) {
|
||||
output = output +"----. "
|
||||
input = input.substring(1, input.length)
|
||||
} else if (input.startsWith("Ä")) {
|
||||
output = output +".-.- "
|
||||
input = input.substring(1, input.length)
|
||||
} else if (input.startsWith("Ö")) {
|
||||
output = output +"---. "
|
||||
input = input.substring(1, input.length)
|
||||
} else if (input.startsWith("Ü")) {
|
||||
output = output +"..-- "
|
||||
input = input.substring(1, input.length)
|
||||
} else if (input.startsWith("ß")) {
|
||||
output = output +"...--... "
|
||||
input = input.substring(1, input.length)
|
||||
} else if (input.startsWith(".")) {
|
||||
output = output +".-.-.- "
|
||||
input = input.substring(1, input.length)
|
||||
} else if (input.startsWith(",")) {
|
||||
output = output +"--..-- "
|
||||
input = input.substring(1, input.length)
|
||||
} else if (input.startsWith(":")) {
|
||||
output = output +"---... "
|
||||
input = input.substring(1, input.length)
|
||||
} else if (input.startsWith(";")) {
|
||||
output = output +"-.-.-. "
|
||||
input = input.substring(1, input.length)
|
||||
} else if (input.startsWith("?")) {
|
||||
output = output +"..--.. "
|
||||
input = input.substring(1, input.length)
|
||||
} else if (input.startsWith("!")) {
|
||||
output = output +"-.-.-- "
|
||||
input = input.substring(1, input.length)
|
||||
} else if (input.startsWith("-")) {
|
||||
output = output +"-....- "
|
||||
input = input.substring(1, input.length)
|
||||
} else if (input.startsWith("_")) {
|
||||
output = output +"..--.- "
|
||||
input = input.substring(1, input.length)
|
||||
} else if (input.startsWith("(")) {
|
||||
output = output +"-.--. "
|
||||
input = input.substring(1, input.length)
|
||||
} else if (input.startsWith(")")) {
|
||||
output = output +"-.--.- "
|
||||
input = input.substring(1, input.length)
|
||||
} else if (input.startsWith("=")) {
|
||||
output = output +"-...- "
|
||||
input = input.substring(1, input.length)
|
||||
} else if (input.startsWith("+")) {
|
||||
output = output +".-.-. "
|
||||
input = input.substring(1, input.length)
|
||||
} else if (input.startsWith("/")) {
|
||||
output = output +"-..-. "
|
||||
input = input.substring(1, input.length)
|
||||
} else if (input.startsWith("@")) {
|
||||
output = output +".--.-. "
|
||||
input = input.substring(1, input.length)
|
||||
} else if (input.startsWith("'")) {
|
||||
output = output +".----. "
|
||||
input = input.substring(1, input.length)
|
||||
} else if (input.startsWith("$")) {
|
||||
output = output +"...-..- "
|
||||
input = input.substring(1, input.length)
|
||||
} else {
|
||||
output = "Code not listed or wrong."
|
||||
}
|
||||
}
|
||||
if (output.endsWith(" ")) {
|
||||
output = output.substring(0, output.length - 18)
|
||||
}
|
||||
}
|
||||
return output
|
||||
}
|
||||
}
|
|
@ -24,7 +24,7 @@ function encrypt(){
|
|||
$("#output").text(encryptWrittenMorseManager(input))
|
||||
} else {
|
||||
//TODO port the normal morse decode engine
|
||||
$("#output").text("The normal morse engine is not ported jet.")
|
||||
$("#output").html(encryptNormalMorseManager(input))
|
||||
}
|
||||
$('#outputcard').fadeIn(dur)
|
||||
}
|
||||
|
|
Reference in a new issue