Discrete Logarithm — Baby-Step Giant-Step

Solve ax ≡ b (mod m). Fill the baby-step table j → aj, then take giant steps b·(a−n)i until one collides with the table. The collision gives x = i·n + j.

step 0

Baby steps — table[aj] = j

filling j = 0 .. n−1
just inserted baby step collision (the answer)

Giant steps — b·(a−n)i

checking i = 0, 1, 2, …
current giant value
No collision yet.
Press Step to begin. We pick n = ⌈√m⌉, fill the baby-step table, then probe it with giant steps.
Phase 1 (left) builds the table; Phase 2 (right) searches it. The collision cell turns green and the result box shows x.
Self-contained visualization. Form B decomposition x = i·n + j with n = ⌈√m⌉. Baby steps store aj for j = 0..n−1; giant steps multiply by a−n = (an)−1 each iteration. A giant value found in the table means aj ≡ b·a−i·n, i.e. ai·n+j ≡ b, so x = i·n + j. Requires gcd(a, m) = 1. See junior.md and professional.md for the correctness proof.
How to read this: the left card fills the baby-step table once (the √m precomputed values). The right card streams giant steps, each one a single multiply by a−n, and probes the table for a match. Because the table lookup is O(1), the whole search costs only O(√m) — two short scans instead of one long O(m) scan. Try a=2, b=5, m=13 (answer x=9), a=3, b=1, m=13 (x=0), or a target outside ⟨a⟩ to watch the “no solution” outcome after all n giant steps. Editing a, b, or m rebuilds the plan instantly.