Skip to content

Instantly share code, notes, and snippets.

@cefaijustin
Created August 19, 2018 20:40
Show Gist options
  • Save cefaijustin/0d9eab9b7eb4d8a405ba43c1e0cde958 to your computer and use it in GitHub Desktop.
Save cefaijustin/0d9eab9b7eb4d8a405ba43c1e0cde958 to your computer and use it in GitHub Desktop.
var alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXWZ";
var cipher = "nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXWZABCDEFGHIJKLM";
function rot13(message){
return message.split('').map(function(c) {
var i = alphabet.indexOf(c);
if (i < 0) {
// not in alphabet, return char
return c;
}
return cipher[i];
}).join('');
}
console.log(rot13("Yeah, it's hot outside too."))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment