-
Notifications
You must be signed in to change notification settings - Fork 0
/
Caesars-Cipher.js
52 lines (49 loc) · 998 Bytes
/
Caesars-Cipher.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
One of the simplest and most widely known ciphers is a Caesar cipher, also known as a shift cipher. In a shift cipher the meanings of the letters are shifted by some set amount.
*/
function rot13(str) { // LBH QVQ VG!
var codex = {
" " : " ",
"A" : "N",
"B" : "O",
"C" : "P",
"D" : "Q",
"E" : "R",
"F" : "S",
"G" : "T",
"H" : "U",
"I" : "V",
"J" : "W",
"K" : "X",
"L" : "Y",
"M" : "Z",
"N" : "A",
"O" : "B",
"P" : "C",
"Q" : "D",
"R" : "E",
"S" : "F",
"T" : "G",
"U" : "H",
"V" : "I",
"W" : "J",
"X" : "K",
"Y" : "L",
"Z" : "M",
"!" : "!",
"?" : "?",
"." : "."
};
//Get lengith for loop
var decodedString = "";
var length = str.length;
var stringExploded = str.split('');
for(var i = 0; i < length; i++){
var letterDecoded = codex[stringExploded[i]];
decodedString = decodedString+letterDecoded;
}
//console.log(decodedString);
return decodedString;
}
// Change the inputs below to test
rot13("SERR CVMMN!");