Skip to content

Instantly share code, notes, and snippets.

@mijimoco
Created February 4, 2017 08:40
Show Gist options
  • Save mijimoco/3a897a0677041b819a07dcf2345c0339 to your computer and use it in GitHub Desktop.
Save mijimoco/3a897a0677041b819a07dcf2345c0339 to your computer and use it in GitHub Desktop.
Caesars Cipher
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