ROT47 with PHP

Tags: October 10, 2005 (3 comments)

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

  1. Logan Kriete
    says

    November 2, 2005 15:59:00+00:00

    Or, you could double rot13 the text - rot26 - for even better encryption! ;-)

  2. Maarburg
    says

    November 3, 2006 08: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

  3. George
    says

    February 12, 2008 17:46:42+00:00

    Thanks for this str_rot47 function!
    Works nicely in my script. :)

Leave a Reply

Yes, comments are moderated.