Skip to content

Instantly share code, notes, and snippets.

@yarkovaleksei
Created June 15, 2016 07:31
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 yarkovaleksei/2d70f03e74f167fd4619b6743ddc3cb9 to your computer and use it in GitHub Desktop.
Save yarkovaleksei/2d70f03e74f167fd4619b6743ddc3cb9 to your computer and use it in GitHub Desktop.
var str = "My top secret phrase!"
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);
});
};
alert(str.rot13());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment