Free tool

Discrete logarithm calculator

Find the exponent x in gx ≡ y (mod p), using baby-step giant-step — and watch how fast the search space runs away from you.

Computing gx mod p is instant. Recovering x from the answer is the discrete logarithm problem, and it is one of the foundations of public-key cryptography. This tool solves it for small primes so you can see both the method and its limits.

Press Solve to search.

Baby-step giant-step needs about √p steps and √p memory, so this tool caps p at 10,000,000. That limit is the whole point — real systems use primes with 600+ digits.

How baby-step giant-step works

Brute force tries every exponent in turn: up to p−1 attempts. Baby-step giant-step trades memory for time and finishes in roughly √p steps instead.

Write x = i·m + j where m = ⌈√(p−1)⌉. Build a table of gj for every small j — the baby steps. Then walk y backwards in strides of m — the giant steps — checking the table each time. A match gives both halves of x.

p = 1,000,003  → brute force ≈ 1,000,000 steps
                    → BSGS ≈ 1,000 steps

That is an enormous speed-up and still nowhere near enough. Square-rooting a 2048-bit number leaves a 1024-bit number — more operations than there are atoms in the observable universe. The gap between "much faster" and "feasible" is where key exchange lives.

Keep going

Discrete logarithms

Why the problem is hard, and how Diffie–Hellman uses it.

Open →

Modular exponentiation

The easy direction, with steps shown.

Open →

Elliptic curves

The same problem on a curve — with much smaller keys.

Open →