Baby-Giant Step Calculator

O(√p) discrete log

CalculatorsFreeNo Signup
4.6(347 reviews)
All Tools

Loading tool...

About Baby-Giant Step Calculator

A Baby-step Giant-step (BSGS) calculator solving g^x ≡ h (mod p). Precomputes baby steps g^j for j=0..m, then checks giant steps h·g^{-im} for matches. Time and space O(√p). Shows the baby and giant step tables. Client-side.

Baby-Giant Step Calculator Features

  • Discrete log
  • Baby steps
  • Giant steps
  • Match finding
  • Step tables
Baby-step Giant-step (Shanks, 1971): solve g^x≡h (mod p). Set m=⌈√(p-1)⌉. Baby steps: compute g^j for j=0,...,m-1. Giant steps: compute h·(g^{-m})^i for i=0,...,m-1. Match at (i,j) gives x=im+j. O(√p) time and space.

How to Use

Enter g, h, p:

  • x: Solution g^x≡h
  • Baby: Precomputed table
  • Giant: Search table

How It Works

Write x=im+j. Then g^{im+j}=h, so g^j=h·g^{-im}. Precompute all g^j (baby steps). Then check h·g^{-im} (giant steps) against the table. First match gives x.

Time-Space Tradeoff

BSGS uses O(√p) memory for the baby step table. This is the classic time-space tradeoff: without the table, brute force takes O(p). With O(√p) space, we reduce to O(√p) time. Often the practical limit is memory, not time.

Step-by-Step Instructions

  1. 1Enter base g.
  2. 2Enter target h.
  3. 3Enter prime p.
  4. 4Compute baby/giant steps.
  5. 5Find match.

Baby-Giant Step Calculator — Frequently Asked Questions

Why is it called Baby-step Giant-step?+

Baby steps increment by 1 (g^0, g^1, g^2,...). Giant steps jump by m (g^{-m}, g^{-2m},...). It's like searching a grid: walk row by row (babies) then jump columns (giants). The metaphor stuck because of Daniel Shanks, who loved vivid names.

What if there's no solution?+

g^x≡h (mod p) has a solution iff h is in the subgroup generated by g. If g is a primitive root mod p, every nonzero h has a solution. Otherwise, check that h^{(p-1)/ord(g)} ≡ 1 first.

How does BSGS compare to Pollard rho for dlog?+

Both are O(√p), but Pollard rho uses O(1) space vs BSGS's O(√p) space. For large p, Pollard rho is more practical (less memory). For small p, BSGS is simpler and deterministic.

Share this tool: