Skip to content
DeepForgeby svx
All problems
HardInformation Theoryinfo-163

Birthday Bound

Problem

Return the number of random hashes needed for a roughly 50 percent chance of a collision when hashes have the given number of bits:

n ~ ceil(sqrt(2 * ln(2) * 2^bits))

This is the birthday bound that sets the security level of hash functions against collisions.

Hint

Collision resistance is only about half the hash length in bits.

Test cases

case 1
in: [8]
expected: 19
case 2
in: [16]
expected: 302
case 3
in: [32]
expected: 77163
case 4
in: [64]
expected: 5056937541
Starter codePython
import math
def birthday_bound(bits):
    # Your code here
    pass

4 test cases · run your code against them in the editor