note 94564 deleted from function.hash by danbrown

From: Date: Thu, 12 Nov 2009 13:32:40 +0000
Subject: note 94564 deleted from function.hash by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-162804@lists.php.net to get a copy of this message
Note Submitter: Brenton Camac ---- Don't be scared off by Kai's pronouncements. MD5 and SHA1 are both hashing algorithms, and there is nothing deficient or broken about them. As hash functions they make no guarantee, by definition, that there won't be "collisions" as Kai puts it. Background: All hash algorithms map their domain (supplied values) onto a typically much smaller range of values (output values). Therefore, its entirely possible that given two distinct inputs, a hashing algorithm will return the same value. Kai is refering to this as a "collision". However, if you are familiar with the principals of hash functions then this won't surprise you. The idea of the functions is not to produce a unique output for every unique input. The idea is to produce some output that is as much as possible, uniformly selected from its output range. This makes these functions a good choice for producing values that can be used as keys in finite arrays (i.e. hashmaps) and hence their name Hash functions. If you want a function that will preserve a 1-1 mapping (i.e. for each distinct input you're guaranteed a distinct output) then don't rely on a hash function as they do not have this property (and Never claimed to have). Mathematically speaking, Hash functions are actually relations not functions. Hope that helps.

« previous php.notes (#162804) next »