Baby-step giant-step
Algorithm for solving the discrete logarithm problem
- 2 min read
- 3 chapters
Related on Lably
Through Algorithm and Big O notation
Many of the most commonly used cryptography systems are based on the assumption that the discrete log is extremely difficult to compute; the more difficult it is, the more security it provides a data transfer. One way to increase the difficulty of the discrete log problem is to base the cryptosystem on a larger group.
Theory
The algorithm is based on a space–time tradeoff. It is a fairly simple modification of trial multiplication, the naive method of finding discrete logarithms.
Given a cyclic group of order , a generator of the group and a group element , the problem is to find an integer such that
The baby-step giant-step algorithm is based on rewriting :
Therefore, we have:
The algorithm precomputes for several values of . Then it fixes an and tries values of in the right-hand side of the congruence above, in the manner of trial multiplication. It tests to see if the congruence is satisfied for any value of , using the precomputed values of .
Sign in to keep reading
2 more chapters are free with a Lably account.
The algorithm
Input: A cyclic group G of order n, having a generator α and an element β.
Output: A value x satisfying .
- m ← Ceiling(√n)
- For all j where 0 ≤ j < m:
- Compute αj and store the pair (j, αj) in a table. (See § In practice)
- Compute α−m.
- γ ← β. (set γ = β)
- For all i where 0 ≤ i < m:
- Check to see if γ is the second component (αj) of any pair in the table.
- If so, return im + j.
- If not, γ ← γ • α−m.
In practice
The best way to speed up the baby-step giant-step algorithm is to use an efficient table lookup scheme. The best in this case is a hash table. The hashing is done on the second component, and to perform the check in step 1 of the main loop, γ is hashed and the resulting memory address checked. Since hash tables can retrieve and add elements in time (constant time), this does not slow down the overall baby-step giant-step algorithm.
The space complexity of the algorithm is , while the time complexity of the algorithm is . This running time is better than the running time of the naive brute force calculation.
The baby-step giant-step algorithm could be used by an eavesdropper to derive the private key generated in the Diffie Hellman key exchange, when the modulus is a prime number that is not too large. If the modulus is not prime, the Pohlig–Hellman algorithm has a smaller algorithmic complexity, and potentially solves the same problem.

