note 16170 added to function.md5

From: Date: Thu, 18 Oct 2001 17:01:28 +0000
Subject: note 16170 added to function.md5
Groups: php.notes 
Request: Send a blank email to php-notes+get-19102@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 -- http://www.php.net/manual/en/function.md5.php http://master.php.net/manage/user-notes.php?action=edit+16170 http://master.php.net/manage/user-notes.php?action=delete+16170 http://master.php.net/manage/user-notes.php?action=reject+16170

« previous php.notes (#19102) next »