3

Possible Duplicate:
Which hashing algorithm is best for uniqueness and speed?

I have created a hash algorithm and would like to test if it is usable. What do I need to test and how?

2

1 Answer 1

4

Short Answer: It depends on many-many factors.

There is no such thing as a good hash function for universal hashes (although there is such a thing as “universal hashing” but it has different meaning).

Depending on the context different criteria determine the quality of a hash. Some people may thing about SHA, however it is a cryptographic hash and it isn't at all good for hash tables which you probably mean.

Longer Answer: Each hash tables has very specific requirements, and still finding a good hash function universally is hard because different data types expose different information that can be hashed. As a rule of thumb it is good to consider all information a type holds equally. This is not always easy or even possible. For reasons of statistics (and hence collision), it is also important to generate a good spread over the problem space, i.e. all possible objects. This means that when hashing numbers between 100 and 1050 it's no good to let the most significant digit play a big part in the hash because for ~ 90% of the objects, this digit will be 0. It's far more important to let the last three digits determine the hash.

Another important thing when hashing strings is to consider all characters (except when it's known in advance that the first three characters of all strings will be the same: because it would be a waste)

Edit:

1) Just to eliminate the confusion between hashing and encryption look here - Fundamental difference between Hashing and Encryption algorithms

2) Also a good discussion on - What is the difference between a Hash Function and a Cryptographic Hash Function?

References to look:

5
  • How exactly could a cryptographic hash function be bad for a hash table (except perhaps for execution speed)? It seems to me that the requirements for a cryptographic hash are strictly greater than for a hash function in a hash table. Dec 16, 2012 at 13:07
  • this sounds to me as a confusion between hashes and cryptographic hash, here is the explanation - security.stackexchange.com/questions/11839/…
    – Yusubov
    Dec 16, 2012 at 13:21
  • no confusion at all, I understand the difference completely, but my question stands: what do you mean when you say "SHA, however it is a cryptographic hash and it isn't at all good for hash tables" Dec 16, 2012 at 13:31
  • digital size and speed was in my mind
    – Yusubov
    Dec 16, 2012 at 13:34
  • 1
    OK, so I'd say we can agree that for those reasons it would not be ideal, but would do the job well enough. Dec 16, 2012 at 13:59

Not the answer you're looking for? Browse other questions tagged or ask your own question.