Last active
August 29, 2015 14:06
-
-
Save joshfreemanIO/8567bc39f1f4d73aaa9f to your computer and use it in GitHub Desktop.
ROT13 - Caeser's Cipher
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(string) { | |
var set = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; | |
var translation = ''; | |
var string_length = string.length; | |
var position; | |
for (var index = 0; index < string_length; index++) { | |
position = set.indexOf(string[index]); | |
if (position >= 0) { | |
translation += set[(position + 13) % 26]; | |
} else { | |
translation += string[index]; | |
} | |
} | |
return translation; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment