|
Posted by Francois Bonzon on 10/20/06 11:40
On 2006-02-20 17:44:26 +0100, Justin Koivisto <justin@koivi.com> said:
> Nel wrote:
>> I am trying to find a php solution to encoding an md5 hex string into
>> another base.
>>
>> Using ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890 as
>> a characters for a base 62
>> i.e.
>> A = 1
>> a = 27
>> 0 = 62
>> 00 = 3844
>> 000 = 238328
>>
>> This should make the hex string much shorter.
>>
>> 1. Does anyone understand what I'm trying to do here?
>> 2. Has this wheel already been invented?
>> 3. Any ideas about the most efficient way to encode and decode this
>> kind of thing?
>
> http://www.pgregg.com/projects/php/base_conversion/base_conversion.php
>
> However, the order that is used on that for the characters are:
>
> 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
>
> (which seems more logical than having the digits at the end)
If you're trying to save memory, IMHO the best way to represent your
MD5 hex string is with binary data. Check out the functions pack() to
encode to binary data, and bin2hex() to decode. Example:
<?
echo $hex_string = md5('abc123'), "\n";
$binary_data = pack('H*', $hex_string);
echo bin2hex($binary_data), "\n";
// Outputs:
// e99a18c428cb38d5f260853678922e03
// e99a18c428cb38d5f260853678922e03
?>
Navigation:
[Reply to this message]
|