Bernd Eber
Bernd Eber

Reputation: 19

Calculating Hash Collisions with 160 bits

Assume a hash function that produces digests of 160 bits. How many messages do we need to hash to get a collision with approximately 75% probability?

Thank you for you help :)

Upvotes: 1

Views: 1353

Answers (2)

Jim Mischel
Jim Mischel

Reputation: 133950

The rule of thumb is that there's a 50% chance of a collision after sqrt(n) numbers are drawn. The number is slightly more than that, but the square root is a good guideline. So in your case you have a 50% chance of collision after 2^80 tries.

The other rule of thumb is that after 4*sqrt(n), your probability of getting a duplicate is nearly a certainty.

According to https://en.wikipedia.org/wiki/Birthday_problem#Probability_of_a_shared_birthday_(collision), you can compute the number, n of values you need to draw to get a probability p of a duplicate by:

n = sqrt(2 * d * ln(1/(1-p)))

Where ln is the natural logarithm, and p is the probability from 0 to 1.0.

So in your case:

n = sqrt(2 * 2^160 * ln(1/.25))
n = sqrt(2^161 * 1.38629)

Which is something less than 2^81.

Upvotes: 1

mypetlion
mypetlion

Reputation: 2524

Somewhere in the range of 2 septillion. That's 2,000,000,000,000,000,000,000,000 messages. Here's the equation.

chance of collision = 1 - e^(-n^2 / (2 * d))

Where n is the number of messages, d is the number of possibilities. So if d is 2^160, then n is going to be in the neighbourhood of 2^80.7.

Upvotes: 0

Related Questions