On Sun, 16 Jun 2002, Danny Kruitbosch wrote:

>-Hi,
>-
>-I'm trying to rewrite a perl finction to php. The function uses Digest::MD5.
>-
>-PHP md5() returns a 32 char hex number. The perl Digest::MD5 function 
>-returns a 16 char (ascii??) string. Can I also get this from PHP? If so 
>-how do I do that?

32 hex characters describes the 128 bit result from the MD5 routine no
matter where it is run: PHP, Shell, whatever.  This assumes one hex
character stands for 4 bits => 32 x 4 = 128.  This is the usual way of
handling MD5 hashes as this is simple 7 bit ascii characters use to
describe the hex numerals 0-9, A, B, C, D, E, and F.

If you use a full byte then you get 8 bits * 16 = 128.  This result is an
extended ascii string which may or may not be difficult to handle with
built-in PHP functions.

You could write a routine that combines every two hex characters into one
byte by converting the right hex to its numerical value (0 to 15), the
left bit to its numerical value * 16, add them together to get the
resulting byte value (0 to 255) and use it to build your 16 byte result.

This should get you compatibility between the two different ways of
describing MD5 hashes.


>-
>-My ultimate goal is to have compatible PHP/Perl functions.
>-
>-
>-Thanks!
>-
>-Danny
>-
>-
>--- 
>-PHP General Mailing List (http://www.php.net/)
>-To unsubscribe, visit: http://www.php.net/unsub.php
>-

**************************************

John Huggins
VANet

[EMAIL PROTECTED]
http://www.va.net/

**************************************


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to