Pollard's rho algorithm for logarithms is an algorithm introduced by
John Pollard in 1978 to solve the
discrete logarithm
In mathematics, for given real numbers ''a'' and ''b'', the logarithm log''b'' ''a'' is a number ''x'' such that . Analogously, in any group ''G'', powers ''b'k'' can be defined for all integers ''k'', and the discrete logarithm log' ...
problem, analogous to
Pollard's rho algorithm
Pollard's rho algorithm is an algorithm for integer factorization. It was invented by John Pollard in 1975. It uses only a small amount of space, and its expected running time is proportional to the square root of the smallest prime factor of th ...
to solve the
integer factorization problem.
The goal is to compute
such that
, where
belongs to a
cyclic group
In group theory, a branch of abstract algebra in pure mathematics, a cyclic group or monogenous group is a group, denoted C''n'', that is generated by a single element. That is, it is a set of invertible elements with a single associative bi ...
generated by
. The algorithm computes
integer
An integer is the number zero (), a positive natural number (, , , etc.) or a negative integer with a minus sign ( −1, −2, −3, etc.). The negative numbers are the additive inverses of the corresponding positive numbers. In the language ...
s
,
,
, and
such that
. If the underlying
group is cyclic of
order
Order, ORDER or Orders may refer to:
* Categorization, the process in which ideas and objects are recognized, differentiated, and understood
* Heterarchy, a system of organization wherein the elements have the potential to be ranked a number of d ...
, by substituting
as
and noting that two powers are equal
if and only if
In logic and related fields such as mathematics and philosophy, "if and only if" (shortened as "iff") is a biconditional logical connective between statements, where either both statements are true or both are false.
The connective is bi ...
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
In arithmetic and computer programming, the extended Euclidean algorithm is an extension to the Euclidean algorithm, and computes, in addition to the greatest common divisor (gcd) of integers ''a'' and ''b'', also the coefficients of Bézout's ...
.
To find the needed
,
,
, and
the algorithm uses
Floyd's cycle-finding algorithm
In computer science, cycle detection or cycle finding is the algorithmic problem of finding a cycle in a sequence of iterated function values.
For any function (mathematics), function that maps a finite set to itself, and any initial value in ...
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: Divide
into three
disjoint subsets
Disjoint may refer to:
*Disjoint sets, sets with no common elements
*Mutual exclusivity, the impossibility of a pair of propositions both being true
See also
*Disjoint union
*Disjoint-set data structure
In computer science, a disjoint-set da ...
of approximately equal size:
,
, and
. If
is in
then double both
and
; if
then increment
, if
then increment
.
Algorithm
Let
be a
cyclic group
In group theory, a branch of abstract algebra in pure mathematics, a cyclic group or monogenous group is a group, denoted C''n'', that is generated by a single element. That is, it is a set of invertible elements with a single associative bi ...
of order
, and given
, and a partition
, let
be the map
:
and define maps
and
by
:
input: ''a'': a generator of ''G''
''b'': an element of ''G''
output: An integer ''x'' such that ''a
x'' = ''b'', or failure
Initialise ''a''
0 ← 0, ''b''
0 ← 0, ''x''
0 ← 1 ∈ ''G''
''i'' ← 1
loop
''x
i'' ← ''f''(''x''
''i''-1),
''a
i'' ← ''g''(''x''
''i''-1, ''a''
''i''-1),
''b
i'' ← ''h''(''x''
''i''-1, ''b''
''i''-1)
''x''
2''i'' ← ''f''(''f''(''x''
2''i''-2)),
''a''
2''i'' ← ''g''(''f''(''x''
2''i''-2), ''g''(''x''
2''i''-2, ''a''
2''i''-2)),
''b''
2''i'' ← ''h''(''f''(''x''
2''i''-2), ''h''(''x''
2''i''-2, ''b''
2''i''-2))
if ''x
i'' = ''x''
2''i'' then
''r'' ← ''b
i'' - ''b''
2''i''
if r = 0 return failure
''x'' ← ''r''
−1(''a''
2''i'' - ''a
i'') mod ''n''
return ''x''
else
// ''xi'' ≠ ''x''2''i''
''i'' ← ''i'' + 1
end if
end loop
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:
#include
const int n = 1018, N = n + 1; /* N = 1019 -- prime */
const int alpha = 2; /* generator */
const int beta = 5; /* 2^ = 1024 = 5 (N) */
void new_xab(int& x, int& a, int& b)
int main(void)
The results are as follows (edited):
i x a b X A B
------------------------------
1 2 1 0 10 1 1
2 10 1 1 100 2 2
3 20 2 1 1000 3 3
4 100 2 2 425 8 6
5 200 3 2 436 16 14
6 1000 3 3 284 17 15
7 981 4 3 986 17 17
8 425 8 6 194 17 19
..............................
48 224 680 376 86 299 412
49 101 680 377 860 300 413
50 505 680 378 101 300 415
51 1010 681 378 1010 301 416
That is
and so
, for which
is a solution as expected. As
is not
prime
A prime number (or a prime) is a natural number greater than 1 that is not a product of two smaller natural numbers. A natural number greater than 1 that is not prime is called a composite number. For example, 5 is prime because the only way ...
, 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
Factor, a Latin word meaning "who/which acts", may refer to:
Commerce
* Factor (agent), a person who acts for, notably a mercantile and colonial agent
* Factor (Scotland), a person or firm managing a Scottish estate
* Factors of production, ...
of
.
References
*
*
{{Number-theoretic algorithms
Logarithms
Number theoretic algorithms