Last active
April 2, 2019 23:44
-
-
Save furf/8b22ed39c861ad17c0685b836754d4d8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function reduceRot13Cipher(map, c, i, abc) { | |
const off = 13; | |
const len = abc.length; | |
const j = (i + off) % len; | |
map[c] = abc[j]; | |
return map; | |
} | |
const rot13 = (() => { | |
const abc = 'abcdefghijklmnopqrstuvwxyz'; | |
const map = {}; | |
abc.split('').reduce(reduceRot13Cipher, map); | |
abc.toUpperCase().split('').reduce(reduceRot13Cipher, map); | |
return function rot13(msg) { | |
const dec = msg.split(''); | |
const enc = dec.map(c => (c in map) ? map[c] : c); | |
return enc.join(''); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment