473,385 Members | 1,555 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

hex to another base

Nel
I am trying to find a php solution to encoding an md5 hex string into
another base.

Using ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwx yz1234567890 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
Feb 20 '06 #1
5 3426
Nel wrote:
I am trying to find a php solution to encoding an md5 hex string into
another base.

Using ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwx yz1234567890 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/b...conversion.php

However, the order that is used on that for the characters are:

0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmn opqrstuvwxyz

(which seems more logical than having the digits at the end)

--
Justin Koivisto, ZCE - ju****@koivi.com
http://koivi.com
Feb 20 '06 #2
On 2006-02-20 17:44:26 +0100, Justin Koivisto <ju****@koivi.com> said:
Nel wrote:
I am trying to find a php solution to encoding an md5 hex string into
another base.

Using ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwx yz1234567890 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/b...conversion.php

However, the order that is used on that for the characters are:

0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmn opqrstuvwxyz

(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

?>

Feb 20 '06 #3
Nel
"Francois Bonzon" wrote in message news:43******@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
Feb 20 '06 #4
Nel
"Justin Koivisto" <ju****@koivi.com> wrote in message
news:U_******************************@onvoy.com...
Nel wrote:
I am trying to find a php solution to encoding an md5 hex string into
another base.

Using ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwx yz1234567890 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/b...conversion.php

However, the order that is used on that for the characters are:

0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmn opqrstuvwxyz

(which seems more logical than having the digits at the end)

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

Perfect Justin ;)
Thanks

Nel
Feb 20 '06 #5
"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.
Feb 21 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Christian Engström | last post by:
When i compile the program listed below with gcc version 3.3.1 (MinGW on Windows XP) I get the following result: Calling 'func(d)': 'base' copy constructor Calling 'func(*d_handle)': 'base'...
39
by: Randell D. | last post by:
Folks, I'm sure this can be done legally, and not thru tricks of the trade - I hope someone can help. I'm writing a 'tool' (a function) which can be used generically in any of my projects. ...
6
by: maadhuu | last post by:
The following is a piece of code and the output of the code is pasted after it . I dont understand how it works (while giving the output) .Can someone enlighten me on this ? thanking you ....
7
by: Lars-Erik Aabech | last post by:
Hi! I've got problems with serializing my collections of business objects. The objects themselves serialize fine, but the collections fail. I've got the following structure: Base collection...
7
by: Sky | last post by:
What I have currently: I have a user control called mod_container.aspx that is basically two divs -- the top a toolbar, that expands/collapse the second div which can contain other...
14
by: Craig Buchanan | last post by:
If I have two custom vb.net classes, where 80% of the properties are alike and there is one method with a matching signature, can i cast between one and the other? do i need to have each class...
2
by: Sathyaish | last post by:
How does a constructor of one class call another of the same class? When would this mechanism make sense or be required? PS: Two instances I saw are: (a) While using the Singleton pattern...
4
by: tired_of_spaghetti | last post by:
I'm curious as to the need for the new keyword in an inherited method redefinition, so - Suppose I have a class hierachy that looks like public class Base { public virtual void myMethod()...
1
by: mflll | last post by:
How does one say in one schema that one wants an element defined in another schema. For example, I want to include in the Employee definition, an Address element defined in the schema...
8
by: bonk | last post by:
When I have an instance of an object wich is of type System.Type, how can I find out if it directly or indirecly derives from another type? myTypeInstance == typeof(AnotherType) only seems to...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.