-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCipher.js
More file actions
40 lines (38 loc) · 676 Bytes
/
Cipher.js
File metadata and controls
40 lines (38 loc) · 676 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
function rot13(str) {
const cipher = {
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',
};
return str.split('').map(word => word in cipher ? cipher[word] : word).join('');
}
console.log(rot13('SERR PBQR PNZC') == 'FREE CODE CAMP');
console.log(rot13('SERR CVMMN!') == 'FREE PIZZA!');
console.log(rot13('SERR YBIR?') == 'FREE LOVE?');
console.log(
rot13('GUR DHVPX OEBJA SBK WHZCF BIRE GUR YNML QBT.') ==
'THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG.'
);