function caesarCipher(str, num) {
[...arr] = str.toLowerCase();
return arr.map((val,indx,input)=> {
if (val.match(/[^a-z]/gi)) return val.charCodeAt(0);
let code = input.join('').charCodeAt(indx) + num;
return ( 96 < code && code < 123) ? code :
(code >= 123) ? code - 26 : code + 26;
});
}
let ans = String.fromCharCode(...caesarCipher('This is very important information',13));
console.log(ans);
Created
December 9, 2017 01:55
-
-
Save carl-parrish/ec1977fe14eff69109427c0014e0e2cf to your computer and use it in GitHub Desktop.
Caesar Cipher
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment