Created
March 18, 2016 13:55
-
-
Save liketaurus/9e0044a444d5b05bf8cf to your computer and use it in GitHub Desktop.
JavaScript function that takes a ROT13 encoded string and decodes it
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) { | |
var result=""; | |
var rot=13; | |
var s=(26-rot)%26; //s=rot; if you want to encrypt! | |
for (var i=0;i<str.length;i++) | |
{ | |
var c = str.charCodeAt(i); | |
if (c>=65 && c<=90) | |
result=result+String.fromCharCode((c-65+s)%26+65); | |
else | |
if (c>=97 && c<=122) | |
result=result+String.fromCharCode((c-97+s)%26+97); | |
else | |
result=result+str.charAt(i); | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment