Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MD5 etc. as a hash function

Tags:

hash

Let's say you are planning to design a hash function which will generate keys between 0-256. Will using first 2 digits of MD5-digest be a great idea for a uniform distribution? What do you think on this? Is it expensive to md5() some word (2-10 letters)?

I know it is a rough definition of requirements but it would be great to discuss this.

like image 225
ahmet alp balkan Avatar asked Feb 25 '23 21:02

ahmet alp balkan


1 Answers

There's no reason to use a cryptographic strength hash for something as simple as generating 3 digit hashes. You're better off using a more simple hash there.

I'm not certain specifically how expensive MD5 is relative to others, but there are plenty of better ways to create a small hash (see this article for some algorithm ideas).

like image 94
Rafe Kettler Avatar answered May 26 '23 02:05

Rafe Kettler