Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

hex to another base

0 views
Skip to first unread message

Nel

unread,
Feb 20, 2006, 11:21:57 AM2/20/06
to
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?

Thanks,

Nel


Justin Koivisto

unread,
Feb 20, 2006, 11:44:26 AM2/20/06
to

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)

--
Justin Koivisto, ZCE - jus...@koivi.com
http://koivi.com

Unknown

unread,
Feb 20, 2006, 11:53:26 AM2/20/06
to

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

?>

Nel

unread,
Feb 20, 2006, 12:23:59 PM2/20/06
to
"Francois Bonzon" wrote in message news:43f9...@epflnews.epfl.ch...

>
> 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
>
> ?>
Hi Francois,

In this cas I am trying to pass a shorter URL and moving from base 16 to 62
knocks off about 10 chars from the URL. Not as many as I'd hoped for, but
it's a definate improvement.

Nel


Nel

unread,
Feb 20, 2006, 12:24:50 PM2/20/06
to
"Justin Koivisto" <jus...@koivi.com> wrote in message
news:U_2dnXUTjtpCbGTe...@onvoy.com...
Perfect Justin ;)
Thanks

Nel


Tim Roberts

unread,
Feb 21, 2006, 2:15:27 AM2/21/06
to
"Nel" <ne...@ne14.co.NOSPAMuk> wrote:
>
>In this cas I am trying to pass a shorter URL and moving from base 16 to 62
>knocks off about 10 chars from the URL. Not as many as I'd hoped for, but
>it's a definate improvement.

You don't have to "hope", you can compute this. The number of bits per
digit is the logarithm in base 2 of the number base. Base 16 packs 4 bits
per digit. Base 62 packs 5.9 bits per digit. The string will be about 1/3
shorter.
--
- Tim Roberts, ti...@probo.com
Providenza & Boekelheide, Inc.

0 new messages