The goal is to compute such that , where belongs to a cyclic group generated by . The algorithm computes integers, , , and such that . If the underlying
order
, by substituting as and noting that two powers are equal if and only if the exponents are equivalent modulo the order of the base, in this case modulo , we get that is one of the solutions of the equation . Solutions to this equation are easily obtained using the extended Euclidean algorithm.
To find the needed , , , and the algorithm uses
Floyd's cycle-finding algorithm
to find a cycle in the sequence , where the function is assumed to be random-looking and thus is likely to enter into a loop of approximate length after steps. One way to define such a function is to use the following rules: Partition into three
disjoint subsets
, , and of approximately equal size using a hash function. If is in then double both and ; if then increment , if then increment .
Algorithm
Let be a cyclic group of order , and given , and a partition , let be the map
and define maps and by
input:a: a generator of Gb: an element of Goutput: An integer x such that ax = b, or failure
Initialise i ← 0, a0 ← 0, b0 ← 0, x0 ← 1 ∈ Gloopi ← i + 1
xi ← f(xi−1),
ai ← g(xi−1, ai−1),
bi ← h(xi−1, bi−1)
x2i−1 ← f(x2i−2),
a2i−1 ← g(x2i−2, a2i−2),
b2i−1 ← h(x2i−2, b2i−2)
x2i ← f(x2i−1),
a2i ← g(x2i−1, a2i−1),
b2i ← h(x2i−1, b2i−1)
whilexi ≠ x2ir ← bi − b2iif r = 0 return failurereturnr−1(a2i − ai) mod n
Example
Consider, for example, the group generated by 2 modulo (the order of the group is , 2 generates the group of units modulo 1019). The algorithm is implemented by the following C++ program:
That is and so , for which is a solution as expected. As is not prime, there is another solution , for which holds.
Complexity
The running time is approximately . If used together with the Pohlig–Hellman algorithm, the running time of the combined algorithm is , where is the largest prime factor of .
References
Pollard, J. M. (1978). "Monte Carlo methods for index computation (mod p)".