Path: blob/master/Discrete-Logarithm-Problem/Algo-Baby-Step-Giant-Step/README.md
2145 views
Baby Step Giant Step Algorithm
Prerequisites:
A method to reduce the time complexity of solving DLP is to use Baby Step Giant Step Algorithm. While brute forcing DLP takes polynomial time of the order
, Baby Step Giant Step Algorithm can compute the value of x in
polynomial time complexity. Here, n is the order of the group.
This algorithm is a tradeoff between time and space complexity, as we will see when we discuss the algorithm.
Algorithm
x can be expressed as x = i*m + j, where
and 0 <= i,j < m.
Hence, we have:

We can now use the above property for solving DLP as follows:
Iterate
jin its range and store all values of
with corresponding values of jin a lookup table.Run through each possible iteration of
iand check if
exists in the table (ie. check if
==
).If it does then return i*m + j as the value of
xElse, continue
Shortcomings
Although the algorithm is more efficient as compared to plain brute-forcing, other algorithms of the same time complexity (Pollard's rho) are used for solving DLPs because of the fact that storing the look up table requires quite a lot of space.
Implementation
I wrote an implementation of the above algorithm in python/sage:
You can check out the complete code here: bsgs.py