Skip to content

Instantly share code, notes, and snippets.

@jsjoeio
Last active May 24, 2017 04:21
Show Gist options
  • Save jsjoeio/0e69578613af371cb408d491b35b7ef3 to your computer and use it in GitHub Desktop.
Save jsjoeio/0e69578613af371cb408d491b35b7ef3 to your computer and use it in GitHub Desktop.
function rot13(str) { // LBH QVQ VG!
debugger;
var newArr = [];
for(var i = 0; i < str.length; i++){
var letter = str.charCodeAt(i);
if (64 < letter && letter < 78){
newArr.push(String.fromCharCode(letter+13));
}
else if(77 < letter && letter < 91){
newArr.push(String.fromCharCode(letter-13));
} else {
newArr.push(String.fromCharCode(letter));
}
}
return newArr.join("");
}
// Change the inputs below to test
rot13("SERR PBQR PNZC");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment