note 88170 deleted from function.str-rot13 by danbrown

From: Date: Wed, 14 Jan 2009 01:03:59 +0000
Subject: note 88170 deleted from function.str-rot13 by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-149160@lists.php.net to get a copy of this message
Note Submitter: joel-php at joelee dot org ---- str-rot13 and asc_shift still generate a fairly readable string. Instead of shifting a constant offset, this scramble function uses XOR and modulus operators into scramble the string into a non-readable binary string. It uses the same function and offset to encrypt and decrypt the string, i.e. you don't have to negate the offset to decrypt. <?php function scramble( $str, $offset ) { $new = ''; $len = strlen($str); for ( $i=0; $i < $len; ++$i ) { $salt = $offset ^ ($len*$i % 256); $new .= chr( ord($str[$i]) ^ $salt ); } return $new; } $str = "TESTING12345@"; echo ( "Original String: {$str}\n" ); $scramble = scramble( $str, 38 ); echo ( "Scrambled String in HEX: ".bin2hex($scramble)."\n" ); $unscramble = scramble( $scramble, 38 ); echo ( "Unscrambled String: {$unscramble}\n" ); ?> Output: Original String: TESTING12345@ Scrambled String in HEX: 726e6f555b292f4c7c60909cfa Unscrambled String: TESTING12345@ Do not use the method to encrypt your critical data. Use MCrypt extension would be a more secure way and compliant with the Industry standard on security.

« previous php.notes (#149160) next »