[kwlug-disc] Hash functions.

Kyle Spaans 3lucid at gmail.com
Sun Jan 2 11:08:39 EST 2011


On Sun, Jan 2, 2011 at 10:59 AM, Khalid Baheyeldin <kb at 2bits.com> wrote:
> On Sun, Jan 2, 2011 at 5:46 PM, Joe Wennechuk
> <youcanreachmehere at hotmail.com> wrote:
>>
>> I want to use a hash type function to generate a unique id for sms
>> messages. I want the smallest possible number of bytes returned as the
>> identifier, I can use all alnum, and even symbols maybe only ASCII up to
>> 127, instead of 256. The input is going to be only 120 chrs+DateTime()+maybe
>> some 10 digit identifier or something, so maybe 200-250 chrs max. for the
>> input, and hopefully like 4-5 chrs for the output with collisions less than
>> 1 in 500,000,000 or so (127^5 is like 33,000,000,000 so that seems
>> ok???).... Is there a function to do this? All the ones I seem to see output
>> in binary or hex only I think I could really reduce the size by using 127
>> chars instaed of 16, and bites are critical to the app. I suppose I could do
>> some parsing on the binary number and come up with something, but I rater
>> just be done with it.
>
> It is unclear to me if you say hex is acceptable or not.
>
> If all you need is a unique hash from a string (however you generate it is
> irrelevant), then a 32 character hash with hex values can be done using
> md5().
>
> $your_hash = md5($your_string);
>
> http://php.net/manual/en/function.md5.php

Yes, it sounds to me like you just want a cryptographic hash, then
run the hash value through a base-64 encoder to get an alphanumeric
value rather than a hexadecimal value.

Alternatively, if security isn't your goal, you could use a CRC, which
should give a smaller output value than MD5 or SHA1.




More information about the kwlug-disc mailing list