There was an error while loading. Please reload this page.
1 parent d3d077e commit 56a521cCopy full SHA for 56a521c
9. Caesar Cipher/CaesarCipher.js
@@ -0,0 +1,23 @@
1
+const allShifts = [...Array(26).keys()]
2
+const cipher = (str, keys=allShifts) => {
3
+ const chars = str.split("")
4
+ const res = keys.map( key => {
5
+ return chars.map( c => {
6
+ const char = c.charCodeAt(0)
7
+ if(char > 64 && char < 91)
8
+ {
9
+ return String.fromCharCode(65 + (char + key) % 65 % 26)
10
+ }
11
+ else if(char > 96 && char < 123)
12
13
+ return String.fromCharCode(97 + (char + key) % 97 % 26)
14
15
+ else
16
17
+ return String.fromCharCode(char)
18
19
+ })
20
21
+
22
+ return res.map( (r, i) => { return { key: keys[i], result: r.join("") } } )
23
+}
0 commit comments