Skip to content

Instantly share code, notes, and snippets.

@joshfreemanIO
Last active August 29, 2015 14:06
Show Gist options
  • Save joshfreemanIO/8567bc39f1f4d73aaa9f to your computer and use it in GitHub Desktop.
Save joshfreemanIO/8567bc39f1f4d73aaa9f to your computer and use it in GitHub Desktop.
ROT13 - Caeser's Cipher
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