Top Description Constructors Methods
org.apache.commons.math3.primes

pack-priv Class PollardRho

extends Object
Class Inheritance
Imports
java.util.ArrayList, .List, org.apache.commons.math3.util.FastMath

Implementation of the Pollard's rho factorization algorithm.
Since
3.2

Constructor Summary

AccessConstructor and Description
private
PollardRho()

Hide utility class.

Method Summary

Modifier and TypeMethod and Description
pack-priv static int

Returns:

gcd(a,b)
gcdPositive
(int
first number, must be ≥ 0
a
,
int
second number, must be ≥ 0
b
)

Gcd between two positive numbers.

public static List<Integer>

Returns:

the list of prime factors of n.
primeFactors
(int
number to factors, must be > 0
n
)

Factorization using Pollard's rho algorithm.

pack-priv static int

Returns:

a prime factor of n.
rhoBrent
(final int
number to factor, must be semi-prime.
n
)

Implementation of the Pollard's rho factorization algorithm.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

PollardRhoback to summary
private PollardRho()

Hide utility class.

Method Detail

gcdPositiveback to summary
pack-priv static int gcdPositive(int a, int b)

Gcd between two positive numbers.

Gets the greatest common divisor of two numbers, using the "binary gcd" method, which avoids division and modulo operations. See Knuth 4.5.2 algorithm B. This algorithm is due to Josef Stein (1961).

Special cases:
  • The result of gcd(x, x), gcd(0, x) and gcd(x, 0) is the value of x.
  • The invocation gcd(0, 0) is the only one which returns 0.
Parameters
a:int

first number, must be ≥ 0

b:int

second number, must be ≥ 0

Returns:int

gcd(a,b)

primeFactorsback to summary
public static List<Integer> primeFactors(int n)

Factorization using Pollard's rho algorithm.

Parameters
n:int

number to factors, must be > 0

Returns:List<Integer>

the list of prime factors of n.

rhoBrentback to summary
pack-priv static int rhoBrent(final int n)

Implementation of the Pollard's rho factorization algorithm.

This implementation follows the paper "An improved Monte Carlo factorization algorithm" by Richard P. Brent. This avoids the triple computation of f(x) typically found in Pollard's rho implementations. It also batches several gcd computation into 1.

The backtracking is not implemented as we deal only with semi-primes.

Parameters
n:int

number to factor, must be semi-prime.

Returns:int

a prime factor of n.