Let us assume that we are given the following:
- The length of the hash
- The chance of obtaining a collision
Now, knowing the above, how can we obtain the number of "samples" needed to obtain the given chance percentage?
Let us assume that we are given the following:
Now, knowing the above, how can we obtain the number of "samples" needed to obtain the given chance percentage?
here is a little javascript function to calculate the chance, based on the "Simplified Approximations" algorithm from https://preshing.com/20110504/hash-collision-probabilities/ (thanks for the link @Frank ) to calculate the chance of collision, and using the Decimal.js bignum library to manage bigger numbers than Javascript's
Number
can handle, example:function:
When we take the
Simplified formula
for the birthday paradox we get:So:
Where we know that n = 2^lenghtHash
A small test: Hash = 16 bit : N= 65536 probability = 50% = 0.5
sqr(0.5*2*65536) =
256 samples
This is not 100% correct as we started of with the Simplified formula, but for big hashes and lager sample sets it gets very close.
for a link on the formula you can look here.