Connecting Tech Pros Worldwide Help | Site Map

Why all hash algorithm are hexadecimal in PHP?

  #1  
Old March 25th, 2008, 10:25 PM
macm
Guest
 
Posts: n/a
Hi Folks

I tested

<?php
echo 'sha256=>' .hash('sha256', 'The quick brown fox jumped over the
lazy dog.') .'</br>';
echo 'sha384=>' .hash('sha384', 'The quick brown fox jumped over the
lazy dog.') .'</br>';
echo 'sha512=>' .hash('sha512', 'The quick brown fox jumped over the
lazy dog.') .'</br>';
echo 'ripemd128=>' .hash('ripemd128', 'The quick brown fox jumped over
the lazy dog.') .'</br>';
echo 'ripemd160=>' .hash('ripemd160', 'The quick brown fox jumped over
the lazy dog.') .'</br>';
echo 'whirlpool=>' .hash('whirlpool', 'The quick brown fox jumped over
the lazy dog.') .'</br>';
echo 'tiger128,3=>' .hash('tiger128,3', 'The quick brown fox jumped
over the lazy dog.') .'</br>';
echo 'tiger160,3=>' .hash('tiger160,3', 'The quick brown fox jumped
over the lazy dog.') .'</br>';
echo 'tiger192,4=>' .hash('tiger192,4', 'The quick brown fox jumped
over the lazy dog.') .'</br>';
echo 'snefru=>' .hash('snefru', 'The quick brown fox jumped over the
lazy dog.') .'</br>';
echo 'gost=>' .hash('gost', 'The quick brown fox jumped over the lazy
dog.') .'</br>';
echo 'adler32=>' .hash('adler32', 'The quick brown fox jumped over the
lazy dog.') .'</br>';
echo 'crc32=>' .hash('crc32', 'The quick brown fox jumped over the
lazy dog.') .'</br>';
echo 'crc32b=>' .hash('crc32b', 'The quick brown fox jumped over the
lazy dog.') .'</br>';
echo 'haval128,3=>' .hash('haval128,3', 'The quick brown fox jumped
over the lazy dog.') .'</br>';
echo 'haval256,5=>' .hash('haval256,5', 'The quick brown fox jumped
over the lazy dog.') .'</br>';
?>

As you can see all results are hexadecimal.

Youtube for example have http://youtube.com/watch?v=n5pkDB7zEeo

n5pkDB7zEeo inst hexadecimal so the comparison is simple.

md5 algorithm have 32^16 = 1,2e^24

youtube algorithm have 11^63 = 405e^63 (because is case sensitive so
combination is [0-9]+[a-Z] + "_" ) (Could have more caracteres!)

So with only 11 caracteres I can have much more combination and much
less collision.

So how can I create a hash algorithm like youtube? with 11 caracteres
[0-9]+[a-Z] + "_"

Some tips? How compile?

Cheers

Mario
  #2  
Old March 25th, 2008, 10:35 PM
larry@portcommodore.com
Guest
 
Posts: n/a

re: Why all hash algorithm are hexadecimal in PHP?


More compact than using decimal and easier to type and/or read (if
needed) than broader full alpha numeric formats.
  #3  
Old March 25th, 2008, 10:45 PM
Jerry Stuckle
Guest
 
Posts: n/a

re: Why all hash algorithm are hexadecimal in PHP?


macm wrote:
Quote:
Hi Folks
>
I tested
>
<?php
echo 'sha256=>' .hash('sha256', 'The quick brown fox jumped over the
lazy dog.') .'</br>';
echo 'sha384=>' .hash('sha384', 'The quick brown fox jumped over the
lazy dog.') .'</br>';
echo 'sha512=>' .hash('sha512', 'The quick brown fox jumped over the
lazy dog.') .'</br>';
echo 'ripemd128=>' .hash('ripemd128', 'The quick brown fox jumped over
the lazy dog.') .'</br>';
echo 'ripemd160=>' .hash('ripemd160', 'The quick brown fox jumped over
the lazy dog.') .'</br>';
echo 'whirlpool=>' .hash('whirlpool', 'The quick brown fox jumped over
the lazy dog.') .'</br>';
echo 'tiger128,3=>' .hash('tiger128,3', 'The quick brown fox jumped
over the lazy dog.') .'</br>';
echo 'tiger160,3=>' .hash('tiger160,3', 'The quick brown fox jumped
over the lazy dog.') .'</br>';
echo 'tiger192,4=>' .hash('tiger192,4', 'The quick brown fox jumped
over the lazy dog.') .'</br>';
echo 'snefru=>' .hash('snefru', 'The quick brown fox jumped over the
lazy dog.') .'</br>';
echo 'gost=>' .hash('gost', 'The quick brown fox jumped over the lazy
dog.') .'</br>';
echo 'adler32=>' .hash('adler32', 'The quick brown fox jumped over the
lazy dog.') .'</br>';
echo 'crc32=>' .hash('crc32', 'The quick brown fox jumped over the
lazy dog.') .'</br>';
echo 'crc32b=>' .hash('crc32b', 'The quick brown fox jumped over the
lazy dog.') .'</br>';
echo 'haval128,3=>' .hash('haval128,3', 'The quick brown fox jumped
over the lazy dog.') .'</br>';
echo 'haval256,5=>' .hash('haval256,5', 'The quick brown fox jumped
over the lazy dog.') .'</br>';
?>
>
As you can see all results are hexadecimal.
>
Youtube for example have http://youtube.com/watch?v=n5pkDB7zEeo
>
n5pkDB7zEeo inst hexadecimal so the comparison is simple.
>
md5 algorithm have 32^16 = 1,2e^24
>
youtube algorithm have 11^63 = 405e^63 (because is case sensitive so
combination is [0-9]+[a-Z] + "_" ) (Could have more caracteres!)
>
So with only 11 caracteres I can have much more combination and much
less collision.
>
So how can I create a hash algorithm like youtube? with 11 caracteres
[0-9]+[a-Z] + "_"
>
Some tips? How compile?
>
Cheers
>
Mario
>
What do y0ou need more than that for? The chances of a collision with
md5 and the rest are VERY remote.

You're much more likely to have a duplicate in the 11 characters than
you will in any of the hashes.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

  #4  
Old March 26th, 2008, 12:15 AM
Jeremy
Guest
 
Posts: n/a

re: Why all hash algorithm are hexadecimal in PHP?


macm wrote:
Quote:
As you can see all results are hexadecimal.
>
Youtube for example have http://youtube.com/watch?v=n5pkDB7zEeo
>
n5pkDB7zEeo inst hexadecimal so the comparison is simple.
>
md5 algorithm have 32^16 = 1,2e^24
>
youtube algorithm have 11^63 = 405e^63 (because is case sensitive so
combination is [0-9]+[a-Z] + "_" ) (Could have more caracteres!)
>
So with only 11 caracteres I can have much more combination and much
less collision.
>
So how can I create a hash algorithm like youtube? with 11 caracteres
[0-9]+[a-Z] + "_"
>
Some tips? How compile?
>
Cheers
>
Mario
Your math is backwards. Youtube's scheme has 63^11 (not 11^63)
combinations, which is about 6.2e19 possibilities.

If you want shorter, url-safe identifiers, you could do something
similar with base64. For example, if you bump the identifier up to 12
characters (multiples of 4 are good for base64) you would get 9 bytes of
data = (2^8)^9 = 2^72 ~= 4.7e21 combinations. Just replace the '/' and
'+' characters from base64 with different, url-safe characters (because
'/' and '+' have meaning in a URI).

Jeremy
  #5  
Old March 26th, 2008, 06:45 AM
NC
Guest
 
Posts: n/a

re: Why all hash algorithm are hexadecimal in PHP?


On Mar 25, 2:21 pm, macm <moura.ma...@gmail.comwrote:
Quote:
>
how can I create a hash algorithm like youtube?
Why do you think it's a hash? It's probably a unique ID represented
as a 62-based number...
Quote:
Some tips? How compile?
If you are content with case-insensitive IDs (meaning 36-based
numbers) you can use base_convert():

http://php.net/base_convert

If you insist on higher base, you would have to write the conversion
routine yourself...

Cheers,
NC
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Encrypting Passwords Cord-Heinrich Pahlmann answers 19 January 12th, 2007 08:35 PM