Created
February 4, 2017 08:40
-
-
Save mijimoco/3a897a0677041b819a07dcf2345c0339 to your computer and use it in GitHub Desktop.
Caesars Cipher
This file contains hidden or 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 rot13(str) { | |
var newArr=[]; | |
for (var i=0; i < str.length; i++) { | |
var char = str.charCodeAt(i); | |
if (char < 65 || char > 90) { | |
newArr.push(str[i]); | |
} else if (char < 78 ) { | |
newArr.push(String.fromCharCode(char+13)); | |
} else { | |
newArr.push(String.fromCharCode(char-13)); | |
} | |
} | |
return newArr.join(''); | |
} | |
console.log(rot13("SERR PBQR PNZC")); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment