public final class SmallPrimes extends Object
Modifier and Type | Method and Description |
---|---|
static int |
boundedTrialDivision(int n,
int maxFactor,
gnu.trove.list.array.TIntArrayList factors)
Extract factors in the range
PRIME_LAST+2 to maxFactors . |
static boolean |
isPrime(int n)
Primality test: tells if the argument is a (provable) prime or not.
|
static boolean |
millerRabinPrimeTest(int n)
Miller-Rabin probabilistic primality test for int type, used in such a way that a result is always guaranteed.
|
static int |
nextPrime(int n)
Return the smallest prime greater than or equal to n.
|
static int[] |
primeFactors(int n)
Prime factors decomposition.
|
static int |
smallTrialDivision(int n,
gnu.trove.list.array.TIntArrayList factors)
Extract small factors.
|
public static boolean isPrime(int n)
It uses the Miller-Rabin probabilistic test in such a way that a result is guaranteed: it uses the firsts prime numbers as successive base (see Handbook of applied cryptography by Menezes, table 4.1).
n
- number to test.public static int nextPrime(int n)
n
- a positive number.IllegalArgumentException
- if n < 0.public static boolean millerRabinPrimeTest(int n)
It uses the prime numbers as successive base therefore it is guaranteed to be always correct. (see Handbook of applied cryptography by Menezes, table 4.1)
n
- number to test: an odd integer ≥ 3public static int smallTrialDivision(int n, gnu.trove.list.array.TIntArrayList factors)
n
- the number to factor, must be > 0.factors
- the list where to add the factors.public static int boundedTrialDivision(int n, int maxFactor, gnu.trove.list.array.TIntArrayList factors)
PRIME_LAST+2
to maxFactors
.n
- the number to factorize, must be >= PRIME_LAST+2 and must not contain any factor below
PRIME_LAST+2maxFactor
- the upper bound of trial division: if it is reached, the method gives up and returns n.factors
- the list where to add the factors.public static int[] primeFactors(int n)
n
- number to factorize: must be ≥ 2IllegalArgumentException
- if n < 2.BigPrimes.primeFactors(cc.redberry.rings.bigint.BigInteger)
Copyright © 2017. All rights reserved.