Some of you may of heard of ROT13 - a simple form of encryption. It uses the 26 letters of the alphabet, splits it in half, and replaces each letter with the letter thirteen places down the alphabet because it is split in half, you can simply use ROT13 on the encrypted string to get it back to normal. In PHP, the function str_rot13() does this.
ROT47 takes ROT13 one step further, instead of using the 26 letters of the alphabet, it uses ASCII codes 33 through 126, making the outputted string far less easy to decrypt in your head. There are a total of 96 characters and to encrypt a string, it replaces each character by whatever character is 47 charaters further on down the list. Like ROT13, ROT47 can just be run on an encrypted string back to normal. Unlike ROT13, PHP does not support it. Here's my basic script:
<?phpif (!function_exists('str_rot47'))
{
function str_rot47($str)
{
return strtr($str, '!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~', 'PQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNO');
}
}?>
Comments
Logan Kriete says…
Edit comment — November 2, 2005 23:59:00+00:00
Or, you could double rot13 the text - rot26 - for even better encryption! ;-)
Maarburg says…
Edit comment — November 3, 2006 16:10:50+00:00
2ROT13
Double ROT13
ROT13 v2.0
Yeah..
Thanks for the script.. I don't do much PHP and this saved me a bunch of time..
I've added this URL to the script at a lame attempt to give you credit for the work.
Maarburg 51 by 157
George says…
Edit comment — February 13, 2008 01:46:42+00:00
Thanks for this str_rot47 function!
Works nicely in my script. :)
Tim says…
Edit comment — March 11, 2011 20:14:20+00:00
or just use http://rot47.com :)