DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

ROT13 //JavaScript Function

11.02.2005
| 13047 views |
  • submit to reddit
        <a href="http://jsfromhell.com/string/rot13">

[UPDATED CODE AND HELP CAN BE FOUND HERE]
</a>

This function codes/decodes strings into ROT13 (rotate the alpha chars by 13 positions...)

//+ Jonas Raoni Soares Silva
//@ http://jsfromhell.com/string/rot13 [v1.0]

String.prototype.rot13 = function(){ //v1.0
	return this.replace(/[a-zA-Z]/g, function(c){
		return String.fromCharCode((c <= "Z" ? 90 : 122) >= (c = c.charCodeAt(0) + 13) ? c : c - 26);
	});
};