Fast Cryptography

This implementation is efficient for operations traditionally used in
cryptography, such as the generation of large prime numbers and computation
of the modular inverse.

Slow Two's Complement Bitwise Operations

This API includes operations for bitwise operations in two's complement
representation. Two's complement is not the internal representation used by
this implementation, so such methods may be inefficient. Use BitSet for high-performance bitwise operations on
arbitrarily-large sequences of bits.

Causes the current thread to wait until another thread invokes the
notify() method or the
notifyAll() method for this object, or
some other thread interrupts the current thread, or a certain
amount of real time has elapsed.

BigInteger

Constructs a random BigInteger instance in the range [0,
pow(2, bitLength)-1] which is probably prime. The probability that the
returned BigInteger is prime is greater than
1 - 1/2<sup>certainty</sup>).

Note: the Random argument is ignored if
bitLength >= 16, where this implementation will use OpenSSL's
BN_generate_prime_ex as a source of cryptographically strong pseudo-random numbers.

BigInteger

Constructs a new BigInteger by parsing value. The string
representation consists of an optional plus or minus sign followed by a
non-empty sequence of decimal digits. Digits are interpreted as if by
Character.digit(char,10).

BigInteger

Constructs a new BigInteger instance by parsing value.
The string representation consists of an optional plus or minus sign
followed by a non-empty sequence of digits in the specified radix. Digits
are interpreted as if by Character.digit(char, radix).

BigInteger

Constructs a new BigInteger from the given two's complement
representation. The most significant byte is the entry at index 0. The
most significant bit of this entry determines the sign of the new BigInteger instance. The array must be nonempty.

bitCount

Returns the number of bits in the two's complement representation of
this which differ from the sign bit. If this is negative,
the result is equivalent to the number of bits set in the two's
complement representation of -this - 1.

Use bitLength(0) to find the length of the binary value in
bits.

Implementation Note: Usage of this method is not recommended as
the current implementation is not efficient.

doubleValue

Returns this BigInteger as a double. If this is too big
to be represented as a double, then Double.POSITIVE_INFINITY or
Double.NEGATIVE_INFINITY is returned. Note that not all integers
in the range [-Double.MAX_VALUE, Double.MAX_VALUE] can be exactly
represented as a double.

Returns

double

the numeric value represented by this object after conversion
to type double.

equals

It is reflexive: for any non-null reference value
x, x.equals(x) should return
true.

It is symmetric: for any non-null reference values
x and y, x.equals(y)
should return true if and only if
y.equals(x) returns true.

It is transitive: for any non-null reference values
x, y, and z, if
x.equals(y) returns true and
y.equals(z) returns true, then
x.equals(z) should return true.

It is consistent: for any non-null reference values
x and y, multiple invocations of
x.equals(y) consistently return true
or consistently return false, provided no
information used in equals comparisons on the
objects is modified.

For any non-null reference value x,
x.equals(null) should return false.

The equals method for class Object implements
the most discriminating possible equivalence relation on objects;
that is, for any non-null reference values x and
y, this method returns true if and only
if x and y refer to the same object
(x == y has the value true).

Note that it is generally necessary to override the hashCode
method whenever this method is overridden, so as to maintain the
general contract for the hashCode method, which states
that equal objects must have equal hash codes.

floatValue

Returns this BigInteger as a float. If this is too big to
be represented as a float, then Float.POSITIVE_INFINITY or
Float.NEGATIVE_INFINITY is returned. Note that not all integers
in the range [-Float.MAX_VALUE, Float.MAX_VALUE] can be exactly
represented as a float.

Returns

float

the numeric value represented by this object after conversion
to type float.

hashCode

Returns a hash code value for the object. This method is
supported for the benefit of hash tables such as those provided by
HashMap.

The general contract of hashCode is:

Whenever it is invoked on the same object more than once during
an execution of a Java application, the hashCode method
must consistently return the same integer, provided no information
used in equals comparisons on the object is modified.
This integer need not remain consistent from one execution of an
application to another execution of the same application.

If two objects are equal according to the equals(Object)
method, then calling the hashCode method on each of
the two objects must produce the same integer result.

It is not required that if two objects are unequal
according to the equals(java.lang.Object)
method, then calling the hashCode method on each of the
two objects must produce distinct integer results. However, the
programmer should be aware that producing distinct integer results
for unequal objects may improve the performance of hash tables.

As much as is reasonably practical, the hashCode method defined by
class Object does return distinct integers for distinct
objects. (This is typically implemented by converting the internal
address of the object into an integer, but this implementation
technique is not required by the
Java™ programming language.)

isProbablePrime

Tests whether this BigInteger is probably prime. If true
is returned, then this is prime with a probability greater than
1 - 1/2<sup>certainty</sup>). If false is returned, then this
is definitely composite. If the argument certainty <= 0, then
this method returns true.

mod

Returns a BigInteger whose value is this mod m. The
modulus m must be positive. The result is guaranteed to be in the
interval [0, m) (0 inclusive, m exclusive). The behavior of this
function is not equivalent to the behavior of the % operator defined for
the built-in int's.

modInverse

Returns a BigInteger whose value is 1/this mod m. The
modulus m must be positive. The result is guaranteed to be in the
interval [0, m) (0 inclusive, m exclusive). If this is
not relatively prime to m, then an exception is thrown.

modPow

Returns a BigInteger whose value is pow(this, exponent) mod modulus. The modulus must be positive. The
result is guaranteed to be in the interval [0, modulus).
If the exponent is negative, then
pow(this.modInverse(modulus), -exponent) mod modulus is computed.
The inverse of this only exists if this is relatively prime to the modulus,
otherwise an exception is thrown.

probablePrime

Returns a random positive BigInteger instance in the range [0, pow(2, bitLength)-1] which is probably prime. The probability that
the returned BigInteger is prime is greater than 1 - 1/2<sup>100</sup>).

shiftLeft

Returns a BigInteger whose value is this << n. The
result is equivalent to this * pow(2, n) if n >= 0. The shift
distance may be negative which means that this is shifted right.
The result then corresponds to floor(this / pow(2, -n)).

Implementation Note: Usage of this method on negative values is
not recommended as the current implementation is not efficient.

toString

Returns a string containing a string representation of this BigInteger with base radix. If radix < Character.MIN_RADIX or
radix > Character.MAX_RADIX then a decimal representation is
returned. The characters of the string representation are generated with
method Character.forDigit.