1
votes

I need a hash that can be represented in less than 26 chars Md5 produces 32 chars long string , if convert it to base 36 how good will it be,

I am need of hash not for cryptography but rather for uniqueness basically identifying each input dependent on time of input and input data. currently i can think of this as

        $hash=md5( str_ireplace(".","",microtime()).md5($input_data) )  ;
        $unique_id= base_convert($hash,16,36) ;

should go like this or use crc32 which will give smaller hash size but i afraid it wont be that unique ?

1
Out of curiosity: why is your unique id limited to 26 characters?Linus Kleen
you're likely to encounter an crc323 collision before a md5 collision. However, i'd use at least sha1 for uniqueness.mbx
It's perfectly acceptable to use a sha-1 hash, then truncate to the desired number of characters. 26 characters should make collisions sufficiently unlikely unless you're dealing with billions of items.Adam Liss
If a collision is a serious problem for you, then you can rule out crc32.srking

1 Answers

1
votes

I think a much simpler solution could take place.

According to your statement, you have 26 characters of space. However, to clarify what I understand to be character and what you understand to be character, let's do some digging.

The MD5 hash acc. to wikipedia produces 16 byte hashes.

The CRC32 algorithm prodces 4 byte hashes.

I understand "characters" (in the most simplest sense) to be ASCII characters. Each ascii character (eg. A = 65) is 8 bits long.

The MD5 aglorithm produces has 16 bytes * 8 bits per byte = 128 bits, CRC32 is 32 bits.

You must understand that hashes are not mathematically unique, but "likely to be unique."

So my solution, given your description, would be to then represent the bits of the hash as ascii characters.

If you only have the choice between MD5 and CRC32, the answer would be MD5. But you could also fit a SHA-1 160 bit hash < 26 character string (it would be 20 ascii characters long).

If you are concerned about the set of symbols that each hash uses, both hashes are in the set [A-Za-z0-9] (I believe).

Finally, when you convert what are essentially numbers from one base to another, the number doesn't change, therefore the strength of the algorithm doesn't change; it just changes the way the number is represented.