Skip to content

Instantly share code, notes, and snippets.

@hengkiardo
Created April 16, 2015 06:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hengkiardo/a171134eef21cda285d3 to your computer and use it in GitHub Desktop.
Save hengkiardo/a171134eef21cda285d3 to your computer and use it in GitHub Desktop.
Encodes and decodes strings into the ROT13 format (rotation of the 26 characters of the alphabet by 13 positions)
String.prototype.rot13 = function(){
return this.replace(/[a-zA-Z]/g, function(c){
return String.fromCharCode((c <= "Z" ? 90 : 122) >= (c = c.charCodeAt(0) + 13) ? c : c - 26);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment