galois.pollard_rho¶
-
galois.pollard_rho(n: int, c: int =
1
) int ¶ Attempts to find a non-trivial factor of
using cycle detection.- Parameters
- Returns
A non-trivial factor
of , if found.None
if not found.- Raises
RuntimeError – If a non-trivial factor cannot be found.
See also
Notes
Pollard’s
algorithm seeks to find a non-trivial factor of by finding a cycle in a sequence of integers defined by where is an unknown small prime factor of . This happens when . Because is unknown, this is accomplished by computing the sequence modulo and looking for .References
Section 3.2.2 from https://cacr.uwaterloo.ca/hac/about/chap3.pdf
Examples
Pollard’s
is especially good at finding small factors.In [1]: n = 503**7 * 10007 * 1000003 In [2]: galois.pollard_rho(n) Out[2]: 503
It is also efficient for finding relatively small factors.
In [3]: n = 1182640843 * 1716279751 In [4]: galois.pollard_rho(n) Out[4]: 1716279751
Last update:
Apr 21, 2022