public final class NumberTheory
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.math.BigInteger |
ONE
BigInteger constant 1
|
static int |
SMALLEST_PRIME_SIZE |
static java.math.BigInteger |
TWO
BigInteger constant 2
|
static java.math.BigInteger |
ZERO
BigInteger constant 0
|
Modifier and Type | Method and Description |
---|---|
static int[] |
extGcd(int a,
int b)
Extended Euclidean algorithm for computing the greatest
common divisor of two integers.
|
static int |
gcd(int a,
int b)
Euclidean algorithm for computing the greatest common divisor
of two integers.
|
static java.math.BigInteger |
getStrongPrime(int x,
java.util.Random random)
Returns a random strong prime.
|
static boolean |
hasSmallFactors(java.math.BigInteger b)
Test the given BigInteger b for small prime factors.
|
static boolean |
isProbablePrime(java.math.BigInteger b)
Perform a probabilistic primality test to determine
if b is prime.
|
static boolean |
millerRabin(java.math.BigInteger n)
Performs the Miller-Rabin probabilistic primality test to determine
if n is prime.
|
static java.math.BigInteger |
nextPrime(java.math.BigInteger b)
Return the smallest prime greater than or equal to b.
|
public static final int SMALLEST_PRIME_SIZE
public static final java.math.BigInteger ZERO
public static final java.math.BigInteger ONE
public static final java.math.BigInteger TWO
public static int gcd(int a, int b)
public static int[] extGcd(int a, int b)
public static java.math.BigInteger nextPrime(java.math.BigInteger b)
public static java.math.BigInteger getStrongPrime(int x, java.util.Random random)
This method implements an algorithm published in RSA LABORATORIES' CryptoBytes, Volume 3, Number 1 - Spring 1997, page 9.
x
- the strength of the prime numberrandom
- the random number generator to usepublic static boolean isProbablePrime(java.math.BigInteger b)
This method only works for positive numbers.
public static boolean millerRabin(java.math.BigInteger n)
This method returns true if n is probable prime and false if it is definitely composite. The probability of returning true if n is composite is less than 2-100 for this implementation.
n
- the integer to be tested (bit length must be >= 160)true
if n is probable prime and false
if it is definitely composite.java.lang.IllegalArgumentException
- if the bit length of the number to be tested
is shorter than 160 bitspublic static boolean hasSmallFactors(java.math.BigInteger b)