Hashing is not a substitute for string comparison

Dec 01 2008

The last day I saw an interesting abuse of hash functions.

In an application that processed strings, there was a part where it compared medium sized strings. Instead of using the in-built string comparison routine, they calculated the hash values of the strings and compared the hashes. Clever?

Wrong!

Finding the hash value (MD5 in this case) of a string is an expensive task. If you do not retain the hash values for future purposes, just compare the strings directly to know whether they are equal.

4 responses so far

Leave a Reply