math - Chance of a duplicate hash when using first 8 characters of SHA1 -


if have index of urls, , id them first 8 characters of sha1 hash, probability of 2 different urls having identical ids?

@teepeemm has correctly answered related question ‘given particular sequence of 8 hex digits, chance of sha-1 hash appearing same 8 digits?’ it's small number.

what's @ stake in question, though, different question: ‘given large number of 8-hex-digit sequences, what's chance of 2 of them being same?’ first comment question points out, related birthday paradox, not ‘what's chance of in room having same birthday me?’, instead ‘what's chance of any 2 people in room having same birthday?’ reasonably known, chance of 50% 23 people.

the hash-collision problem same problem, generalised n=365 days n=16^8 8-byte sequences, 4.30e9. that's ‘generalised birthday problem’. using expression quoted there (n=sqrt(2*d*ln(1/(1-p))), d=4.30e9 , p=0.5, find 50% chance of collision 77000 trials. if plot corresponding function, see probability increases quite rapidly number of trials increases.

even 16 bytes of hash (so d=16^16) there's 50% chance of collision after 5 billion trials.

happy birthday!


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -