Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

ROT13 //JavaScript Function

DZone's Guide to

ROT13 //JavaScript Function

·
Free Resource


[UPDATED CODE AND HELP CAN BE FOUND HERE]


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);
	});
};
Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}