-
Notifications
You must be signed in to change notification settings - Fork 0
/
cesars_cipher.js
35 lines (28 loc) · 884 Bytes
/
cesars_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
function rot13(str) {
let x = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M']
let y = ['N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
let strArr = str.split('')
let newArr = []
let format = /^[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]*$/
strArr.forEach(letter => {
for(let i = 0; i < x.length; i++) {
if(letter === ' ') {
newArr.push(' ')
break
}
if(letter === x[i]) {
newArr.push(y[i])
}
if(letter === y[i]) {
newArr.push(x[i])
}
if(letter.match(format)) {
newArr.push(letter)
break
}
}
});
let newStr = newArr.join('')
console.log(newStr)
}
rot13("GUR DHVPX OEBJA SBK WHZCF BIRE GUR YNML QBT.");