Skip to content

Instantly share code, notes, and snippets.

@vg22
Created June 11, 2016 16:53
Show Gist options
  • Save vg22/7fcea1a7139194d61e12ff868669f360 to your computer and use it in GitHub Desktop.
Save vg22/7fcea1a7139194d61e12ff868669f360 to your computer and use it in GitHub Desktop.
function rot13(str) { // LBH QVQ VG!
var i=0,j=0;var newstr=[];
while(i<str.length){
if(str.charCodeAt(i)>64&&str.charCodeAt(i)<78){
j=str.charCodeAt(i)+13;
newstr.push(String.fromCharCode(j));
}
else if(str.charCodeAt(i)>77&&str.charCodeAt(i)<=90){
j=str.charCodeAt(i)-13;
newstr.push(String.fromCharCode(j));
}
else {
newstr.push(str.charAt(i));
console.log(newstr.push(str.charAt(i)));
}
i++;
}
return newstr.join('');
console.log(newstr.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