Convert md5 hash to contain ALL letters

I noticed that md5() seems to only return hexadecimal values.

Is there a way to convert that to something that contains letters all the way to z?

If not is there another similar hash that can do this?
LVL 16
hankknightAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Michael701Commented:
I guess you'd take the decimal value, then convert to base 26 (assigning the results to a-z)

but why?
0
hernst42Commented:
md5 only uses hex-chars because it's the most easiest way to encode and decode 128bits. You can write you own function to convert the 8-byte (128bit) String in any other encoding you like, but it's a lot of bit juggeling. You could use http://www.php.net/manual/en/function.convert-uuencode.php or http://www.php.net/manual/en/function.base64-encode.php which pack more bits into a single char
0
BenMorelCommented:
Hi,
You need to base-convert the md5() function result, from a 16-chars base (md5 hex) to a 62-chars base (0-9 a-z A-Z).
Since php's built-in functions still rely on approximative float (double) types to do that, I use custom-made functions based on the bc lib (should be available in most php builds).
At the very bottom, a function CustomMD5() you can use instead of md5().
Regards,
Ben
<?php
define('HEX_CHARS',    '0123456789abcdef');
define('BASE62_CHARS', '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ');
 
/*********************************************/
function ConvertFromArbitraryBase($Str, $Chars)
/*********************************************/
{
    /*
        Converts from an arbitrary-base string to a decimal string
    */
    
    if (ereg('^[' . $Chars . ']+$', $Str))
    {
        $Result = '0';
        
        for ($i=0; $i<strlen($Str); $i++)
        {
            if ($i != 0) $Result = bcmul($Result, strlen($Chars));
            $Result = bcadd($Result, strpos($Chars, $Str[$i]));
        }
        
        return $Result;
    }
    
    return false;
}
 
/*******************************************/
function ConvertToArbitraryBase($Str, $Chars)
/*******************************************/
{
    /*
        Converts from a decimal string to an arbitrary-base string
    */
 
    if (ereg('^[0-9]+$', $Str))
    {
        $Result = '';
        
        do
        {
            $Result .= $Chars[bcmod($Str, strlen($Chars))];
            $Str = bcdiv($Str, strlen($Chars));
        }
        while (bccomp($Str, '0') != 0);
        
        return strrev($Result);
    }
    
    return false;
}
 
/**********************/
function CustomMD5($Str)
/**********************/
{
	return ConvertToArbitraryBase(ConvertFromArbitraryBase(md5($Str), HEX_CHARS), BASE62_CHARS);
}
?>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.