GB_001 Posted September 17, 2010 Share Posted September 17, 2010 Hello, I created a system where emails get encrypted with a random key that gets stored in a database, what are the odds of the Hashes Colliding? Part of the code: function genRandomString($num) { $length = $num; $characters = '0123456789abcdefghijklmnopqrstuvwxyz'; $string = ""; for ($p = 0; $p < $length; $p++) { $string .= $characters[mt_rand(0, strlen($characters))]; } return $string;}$Key=genRandomString(10);$email_s=hash_hmac('ripemd160', $email, $Key); Thankyou, GB. Quote Link to comment Share on other sites More sharing options...
the182guy Posted September 17, 2010 Share Posted September 17, 2010 It's impossible to calculate the odds because the length of the random string is dynamic (passed in as an argument to the function). The longer the string, the longer the odds. If you really want to test this then create a script which constantly calls your function and stores the results in a MySQL table, leave it running for some time to get a few thousand records....or more. Then do a SELECT DISTINCT query on the table and if the distinct row count matches the actual row count then you know they are all unique. Another option here is to use uniq() and then hash() it using your preferred algo. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.