Created
June 11, 2016 16:53
-
-
Save vg22/7fcea1a7139194d61e12ff868669f360 to your computer and use it in GitHub Desktop.
This file contains 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) { // 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