Apex › Cryptography

Cracking a discrete log (baby-step giant-step)

Diffie–Hellman rests on the discrete log being hard: given g, p, and h = gˣ mod p, find x. Brute force takes p steps; baby-step giant-step meets in the middle for O(√p). Write x = i·m + j (m = ⌈√(p−1)⌉), so h·(g⁻ᵐ)ⁱ = gʲ; precompute a table of all gʲ (baby steps), then stride h by g⁻ᵐ (giant steps) until one lands in the table — the collision gives x = im + j. It’s the discrete-log counterpart to Pollard’s rho. Produce it: climb the primes 23 → 503 and watch the baby table grow as √p while the speedup rises 2.9× → 19×. Then hit the wall — a cost chart shows √p only HALVES the exponent, so it stays exponential: it cracks these toy primes (and any weak or smooth group), but a 256-bit group needs 2¹²⁸ operations and stays safe. A b-bit group gives only ~b/2 bits of security; node-verified across 5 primes with visible strides.

More in Cryptography