note 94564 added to function.hash

From: Date: Thu, 12 Nov 2009 07:49:12 +0000
Subject: note 94564 added to function.hash
Groups: php.notes 
Request: Send a blank email to php-notes+get-162793@lists.php.net to get a copy of this message
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. ---- Server IP: 69.147.83.197 Probable Submitter: 76.115.198.6 ---- Manual Page -- http://www.php.net/manual/en/function.hash.php Edit -- https://master.php.net/note/edit/94564 Del: integrated -- https://master.php.net/note/delete/94564/integrated Del: useless -- https://master.php.net/note/delete/94564/useless Del: bad code -- https://master.php.net/note/delete/94564/bad+code Del: spam -- https://master.php.net/note/delete/94564/spam Del: non-english -- https://master.php.net/note/delete/94564/non-english Del: in docs -- https://master.php.net/note/delete/94564/in+docs Del: other reasons-- https://master.php.net/note/delete/94564 Reject -- https://master.php.net/note/reject/94564 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#162793) next »