-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCaesarsCipher.js
More file actions
50 lines (46 loc) · 904 Bytes
/
CaesarsCipher.js
File metadata and controls
50 lines (46 loc) · 904 Bytes
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
function rot13(str) {
var lookup = {
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",
" ": " ",
"!": "!",
"?": "?",
".": ".",
};
var ar = [];
var newArr = []; //[ 'F', 'R', 'E', 'E', ' ', 'C', 'O', 'D', 'E', ' ', 'C', 'A', 'M', 'P' ]
ar = str.split(""); //[ 'S', 'E', 'R', 'R', ' ', 'P', 'B', 'Q', 'R', ' ', 'P', 'N', 'Z', 'C' ]
console.log(ar);
for (var i = 0; i < ar.length; i++) {
let lookupValue = ar[i];
let matchingValue = lookup[lookupValue];
newArr.push(matchingValue);
}
var newStr = newArr.join(",").replace(/,/g, ""); // FREE CODE CAMP
return newStr;
}
rot13("SERR PBQR PNZC");