note 16170 deleted from function.md5 by jimw

From: Date: Sat, 03 Nov 2001 02:34:47 +0000
Subject: note 16170 deleted from function.md5 by jimw
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-20336@lists.php.net to get a copy of this message
I need functions to encrypt and decrypt strings. The code from Alexander Yanuar is completely perfect to me. With only one problem: the string in return contains a sort of non-visible characters. Solution? Perhaps is not the better, but using the function bin2hex we get a more usable string (and longer). There is not hex2bin in the standar function library of PHP, then i take the function hex2bin of josh@superfork.com Now, adding the next functions to the original (and marvellous) code of Alexander Yanuar we have a enconding function and a decoding function with only one parameter. function hex2bin($data) { $len = strlen($data); for($i=0;$i<$len;$i+=2) { $newdata .= pack("C",hexdec(substr($data,$i,2))); } return $newdata; } function enc($tmp) { $tmp = encrypt($tmp,$key); return (bin2hex($tmp)); } function dec($tmp) { $tmp = hex2bin($tmp); return (decrypt($tmp,$key)); } ------------------------ Juan Jose Ferres Serrano gunkan@terra.es

« previous php.notes (#20336) next »