Intuition, Vocabulary and Foundations
A discrete logarithm reverses repeated group multiplication. If $g$ generates a cyclic subgroup of order $n$, solving $g^x=h$ means finding the position of $h$ on the cycle $1,g,g^2,\ldots,g^{n-1}$. Modulo $29$, for example, $2^{11}\equiv18$, so the logarithm of $18$ to base $2$ is $11$.
Linear search may inspect all $n$ exponents. Baby-step giant-step writes $x=im+j$, with $m=\lceil\sqrt n\rceil$, and searches for a collision $h(g^{-m})^i=g^j$. Pohlig–Hellman exploits a factorization $n=\prod q_i^{e_i}$: it finds $x$ modulo every prime power and reconstructs $x\bmod n$ with CRT.
BSGS splits one search into two dimensions of size about $\sqrt n$. Pohlig–Hellman goes further when the exact order is smooth: project into small prime-order problems, recover exponent digits, and combine the prime-power residues with CRT.
| Concept | Example | Boundary or non-example | Question answered |
|---|---|---|---|
| Cyclic subgroup | $\langle2\rangle$ modulo $29$ has order $28$ | A target outside $\langle g\rangle$ has no log to base $g$ | Which elements are reachable? |
| Collision | $h(g^{-m})^i=g^j$ gives $x\equiv im+j\pmod n$ | Equality in another group proves nothing | How does BSGS recover an exponent? |
| Smooth order | $28=2^2\cdot7$ | An order with one huge prime factor is not smooth | Is Pohlig–Hellman advantageous? |
| Prime-power residue | Residues modulo $4$ and $7$ determine one residue modulo $28$ | Ordinary CRT does not directly merge non-coprime moduli | What does each projection recover? |
| Exact order | $g^n=1$ and $g^{n/q}\ne1$ for each prime $q\mid n$ | A mere multiple of the order loses uniqueness | Modulo what value is the log unique? |
Step-by-Step Derivations and Algorithms
For BSGS, store $g^j$ for $0\le j\lt m$. Starting with $\gamma=h$, multiply by $g^{-m}$ after every lookup. At iteration $i$, the invariant is $\gamma=h(g^{-m})^i$. A table match $\gamma=g^j$ yields $h=g^{im+j}$; verify the candidate before returning it.
For Pohlig–Hellman, factor $n=\prod q^e$ and write $x=d_0+d_1q+\cdots+d_{e-1}q^{e-1}$. If $x_k=\sum_{j=0}^{k-1}d_jq^j$ is known, then
$$c_k=\left(hg^{-x_k}\right)^{n/q^{k+1}}=\left(g^{n/q}\right)^{d_k}.$$
The base $g^{n/q}$ has order $q$, so a small discrete-log call recovers digit $d_k$. The completed residues modulo the distinct $q^e$ factors are pairwise coprime and CRT reconstructs the unique answer modulo $n$.
flowchart TD
A[Validate exact order and membership] --> B{Factorization available?}
B -->|No| C[Run BSGS in order n]
B -->|Yes| D[Split n into prime powers]
D --> E[Recover base-q digits]
E --> F[Combine residues with CRT]
C --> G[Verify exponent]
F --> G
G --> H[Return log or no solution]
BSGS maintains $\gamma=hg^{-im}$ and uses $O(\sqrt n)$ group operations and stored elements. Pohlig–Hellman preserves the already recovered low-order digits of $x$ and requires about $O(\sum_i e_i\sqrt{q_i})$ generic subgroup work, so its cost is governed chiefly by the largest prime factor.
Implementation, Complexity and Engineering
The reference implementation works in the multiplicative group modulo a prime. It proves that the supplied order is exact, checks target membership before allocating a table, returns None for a missing solution, validates the complete factorization, and verifies the final exponent. For large inputs, estimate the BSGS table first: an $80$-bit prime-order subgroup would require roughly $2^{40}$ entries.
| Method | Time and memory | Failure mode | Mitigation |
|---|---|---|---|
| Linear search | $O(n)$ time, $O(1)$ memory | Too slow beyond tiny groups | Use only as a testing oracle |
| BSGS | $O(\sqrt n)$ time and memory | Table exceeds memory | Estimate entries first or use a rho method |
| Pohlig–Hellman | About $O(\sum e_i\sqrt{q_i})$ subgroup work | One large prime factor dominates | Measure security by the largest prime-order component |
| Supplied order | Avoids order discovery | A multiple of the true order breaks uniqueness | Test $g^{n/q}\ne1$ for every prime $q\mid n$ |
| Membership check | One exponentiation $h^n$ | Unsafe if the base order is not exact | Validate exact order first |
| CRT | Efficient across prime-power factors | Ordinary CRT needs coprime moduli | Combine distinct prime powers only |
Applications, Case Studies and Exercises
For $p=29$, $g=2$, and $h=18$, BSGS with $m=6$ finds $x=11$. Pohlig–Hellman uses $28=4\cdot7$, recovers $x\equiv3\pmod4$ and $x\equiv4\pmod7$, and CRT returns $11\pmod{28}$. In security engineering, this structure explains why a large total group order is insufficient: if it is smooth, the discrete logarithm decomposes into inexpensive problems.
Apply Baby-Step Giant-Step & Pohlig-Hellman
Case study 1. Build the BSGS table for $p=29$, $g=2$, $h=18$, and $m=6$; trace giant steps to the collision and verify $2^{11}\equiv18$. Then derive the residues modulo $4$ and $7$. Success means CRT returns $11$.
Case study 2. Compare groups of orders $2^{10}3^6$ and $2q$, where $q$ is a large prime of comparable bit length. Estimate the largest subgroup table and list required membership checks. Success means the security comparison is based on the largest prime factor.
Exercises. Prove the BSGS collision equation; derive one Pohlig–Hellman digit step; exhaustively compare both solvers with direct search in small fields; reject wrong orders, incomplete factorizations, and outside-subgroup targets; add a table-size limit and operation counters.
Use direct search only as a tiny oracle, BSGS for moderate generic orders when square-root memory is acceptable, and Pohlig–Hellman for known smooth orders. Never confuse a multiple of the base order with its exact order or assess cryptographic strength from total group size alone; subgroup validation and the largest prime factor determine the real boundary.