note 88170 added to function.str-rot13

From: Date: Tue, 13 Jan 2009 19:19:44 +0000
Subject: note 88170 added to function.str-rot13
Groups: php.notes 
Request: Send a blank email to php-notes+get-149149@lists.php.net to get a copy of this message
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. ---- Server IP: 87.124.35.190 Probable Submitter: 89.105.99.83 ---- Manual Page -- http://www.php.net/manual/en/function.str-rot13.php Edit -- https://master.php.net/note/edit/88170 Del: integrated -- https://master.php.net/note/delete/88170/integrated Del: useless -- https://master.php.net/note/delete/88170/useless Del: bad code -- https://master.php.net/note/delete/88170/bad+code Del: spam -- https://master.php.net/note/delete/88170/spam Del: non-english -- https://master.php.net/note/delete/88170/non-english Del: in docs -- https://master.php.net/note/delete/88170/in+docs Del: other reasons-- https://master.php.net/note/delete/88170 Reject -- https://master.php.net/note/reject/88170 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#149149) next »