Skip to content

Instantly share code, notes, and snippets.

@vg22
Created June 10, 2016 19:42
Show Gist options
  • Save vg22/5148fcfd09f6fde01e73c4be7398dd11 to your computer and use it in GitHub Desktop.
Save vg22/5148fcfd09f6fde01e73c4be7398dd11 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){
//(str.charCodeAt(i)<77){
//newstr[i]=str.charCodeAt(i)+13;
j=str.charCodeAt(i)+13;
//console.log(j);
//console.log(String.fromCharCode(newstr[i]));
newstr.push(String.fromCharCode(j));
//console.log(newstr);
}
else if(str.charCodeAt(i)>77||str.charCodeAt(i)<90){
j=str.charCodeAt(i)-13;
newstr.push(String.fromCharCode(j));
//newstr[i]=str.charCodeAt(i)-13;
//console.log(String.fromCharCode(newstr[i]));
//newstr.push(String.fromCharCode(newstr[i]));
//console.log(newstr);
}
else{
newstr.push(" ");
}
i++;
}
return newstr.join("");
console.log(newstr.join(""));
}
/*console.log(newstr);
while(i<str.length){
if(newstr.charCodeAt(i)>77)
{
j=j-13;
console.log(String.fromCharCode(newstr[i]));
}
else
{
j+=13;
console.log(String.fromCharCode(newstr[i]));
}
i++;
}
//return String.fromCharCode(j);
}
}*/
// 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