de.bb.minissl
Class BigInteger

java.lang.Object
  |
  +--de.bb.minissl.BigInteger

public class BigInteger
extends java.lang.Object

A small and fast implementation for BigInteger. Like the String class, all public functions do not modify an existing BigInteger, but return a new created BigInteger with the result.


Field Summary
static BigInteger ONE
           
static BigInteger TEN
           
static BigInteger THREE
           
static BigInteger TWO
           
static BigInteger ZERO
           
 
Constructor Summary
BigInteger()
          default ct, constructs a BigInteger with value 0.
BigInteger(byte[] d)
          Create a BigInteger from a byte array, which is interpreted as a big endian number.
BigInteger(int bitLength, int certainty, java.util.Random rand)
          Create a prime number for given bit length.
BigInteger(int bitLength, java.util.Random rand)
          Create a random number for given bit length.
BigInteger(long l)
          Create a BigInteger from a long value.
BigInteger(java.lang.String s)
          Create a BigInteger from a String, the String is expected to contain some number with radix 10.
BigInteger(java.lang.String s, int radix)
          Create a BigInteger from a String, the String is expected to contain some number with the given radix.
 
Method Summary
 BigInteger add(BigInteger o)
          Add to this number the value o, and return a new BigInteger containing the result. pseudo: return this + o
 int bitLength()
          Return the count of used bits.
 java.lang.Object clone()
          Clone this BigInteger.
 int compareTo(BigInteger o)
          Compare this BigInteger to another BigInteger.
 BigInteger divide(BigInteger div)
          Divide this number by the value o, and return a new BigInteger containing the result. pseudo: return this / o
 BigInteger[] divideAndRemainder(BigInteger div)
          Calculate the division and modulo for this number by the value o, and return a new BigInteger array containing the results. pseudo: return {this / o, this mod o }
 BigInteger gcd(BigInteger b)
          Calculate the greatest common divisor.
 int getLowestSetBit()
          Get the index of the lowest set bit.
 boolean isProbablePrime(java.util.Random rand, int numChecks)
          Performs a check whether this number is probably prime.
 BigInteger mod(BigInteger div)
          Calculate the modulo for this number by the value o, and return a new BigInteger containing the result. pseudo: return this mod o
 BigInteger modInverse(BigInteger n)
          Calculate the modulo inverse for this number by the value n, and return a new BigInteger containing the result. pseudo: solves a * result == 1 (mod n)
 BigInteger modPow(BigInteger exp, BigInteger mod)
          Calculate this^exp % mod.
 BigInteger multiply(BigInteger o)
          Multiply this number by the value o, and return a new BigInteger containing the result. pseudo: return this * o
 BigInteger negate()
          Create a BigInteger with - this value. x.negate() + x = 0
 BigInteger shiftLeft(int n)
          Calculate the left shift for this number by the value n, and return a new BigInteger containing the result. pseudo: return this << n
 BigInteger shiftRight(int n)
          Calculate the rights shift for this number by the value n, and return a new BigInteger containing the result. pseudo: return this >> n
 BigInteger subtract(BigInteger o)
          Subtract from this number the value o, and return a new BigInteger containing the result. pseudo: return this - o
 byte[] toByteArray()
          Convert this BigInteger into a byte array.
 java.lang.String toHexString()
          Convert this BigInteger into an hex string.
 java.lang.String toString()
          Convert this BigInteger into a decimal string.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ZERO

public static final BigInteger ZERO

ONE

public static final BigInteger ONE

TWO

public static final BigInteger TWO

THREE

public static final BigInteger THREE

TEN

public static final BigInteger TEN
Constructor Detail

BigInteger

public BigInteger()
default ct, constructs a BigInteger with value 0.

BigInteger

public BigInteger(int bitLength,
                  int certainty,
                  java.util.Random rand)
Create a prime number for given bit length.
Parameters:
bitLength - the desired bit length of the prime.
certainty - how sure is it a prim P = 1 - (1/2)^certainty.
rand - the random generator for random numbers.

BigInteger

public BigInteger(int bitLength,
                  java.util.Random rand)
Create a random number for given bit length.
Parameters:
bitLength - the desired bit length of the number.
rand - the random generator for random numbers.

BigInteger

public BigInteger(long l)
Create a BigInteger from a long value.
Parameters:
l - the long value which is assigned to this BigInteger.

BigInteger

public BigInteger(java.lang.String s)
Create a BigInteger from a String, the String is expected to contain some number with radix 10.
Parameters:
s - input string, containing a number with radix 10.

BigInteger

public BigInteger(java.lang.String s,
                  int radix)
Create a BigInteger from a String, the String is expected to contain some number with the given radix.
Parameters:
s - input string, containing a number with the given radix.
radix - the radix to use, right now 10 and 16 are supported.

BigInteger

public BigInteger(byte[] d)
Create a BigInteger from a byte array, which is interpreted as a big endian number. If the highest bit is set, the number is treated as a negative number.
Parameters:
d - input byte array.
Method Detail

toHexString

public java.lang.String toHexString()
Convert this BigInteger into an hex string.
Returns:
a new String containing the hex value of this BigInteger.

toString

public java.lang.String toString()
Convert this BigInteger into a decimal string.
Overrides:
toString in class java.lang.Object
Returns:
a new String containing the decimal value of this BigInteger.

clone

public java.lang.Object clone()
Clone this BigInteger.
Overrides:
clone in class java.lang.Object
Returns:
a new BigInteger containing the same value.

toByteArray

public byte[] toByteArray()
Convert this BigInteger into a byte array.
Returns:
a new alloctaed byte array containing the bytes of this BigInteger.

subtract

public BigInteger subtract(BigInteger o)
Subtract from this number the value o, and return a new BigInteger containing the result. pseudo: return this - o
Parameters:
o - the subtracted value

add

public BigInteger add(BigInteger o)
Add to this number the value o, and return a new BigInteger containing the result. pseudo: return this + o
Parameters:
o - the added value

multiply

public BigInteger multiply(BigInteger o)
Multiply this number by the value o, and return a new BigInteger containing the result. pseudo: return this * o
Parameters:
o - the multiplicator.

divide

public BigInteger divide(BigInteger div)
Divide this number by the value o, and return a new BigInteger containing the result. pseudo: return this / o
Parameters:
div - the divisor.

mod

public BigInteger mod(BigInteger div)
Calculate the modulo for this number by the value o, and return a new BigInteger containing the result. pseudo: return this mod o
Parameters:
div - the modulo.

divideAndRemainder

public BigInteger[] divideAndRemainder(BigInteger div)
Calculate the division and modulo for this number by the value o, and return a new BigInteger array containing the results. pseudo: return {this / o, this mod o }
Parameters:
div - the divisor/modulo.

modInverse

public BigInteger modInverse(BigInteger n)
Calculate the modulo inverse for this number by the value n, and return a new BigInteger containing the result. pseudo: solves a * result == 1 (mod n)
Parameters:
n - the modulo.

compareTo

public int compareTo(BigInteger o)
Compare this BigInteger to another BigInteger.
Parameters:
o - the other BigInteger.
Returns:
-1 if this < o, 0 if this == o, 1 if this > o.

getLowestSetBit

public int getLowestSetBit()
Get the index of the lowest set bit.
Returns:
The index of the lowest set bit.

shiftLeft

public BigInteger shiftLeft(int n)
Calculate the left shift for this number by the value n, and return a new BigInteger containing the result. pseudo: return this << n
Parameters:
n - Count of left shifts.
Returns:
a new allocated BigInteger containing the result.

shiftRight

public BigInteger shiftRight(int n)
Calculate the rights shift for this number by the value n, and return a new BigInteger containing the result. pseudo: return this >> n
Parameters:
n - Count of right shifts.
Returns:
a new allocated BigInteger containing the result.

bitLength

public int bitLength()
Return the count of used bits.
Returns:
Return the count of used bits.

isProbablePrime

public boolean isProbablePrime(java.util.Random rand,
                               int numChecks)
Performs a check whether this number is probably prime. The probability is 1 - (1/2)^numChecks.
Parameters:
rand - the used randomgenerator to perform the checks.
numChecks - count of performed checks
Returns:
false if it's definitely not a prime, true either.

gcd

public BigInteger gcd(BigInteger b)
Calculate the greatest common divisor. So (this / result) is prime to (b / result).
Parameters:
b - the 2nd BigInteger.
Returns:
a new BigInteger containing the greatest common divisor.

modPow

public BigInteger modPow(BigInteger exp,
                         BigInteger mod)
Calculate this^exp % mod. Right now it works only for even modulus.
Parameters:
exp - the exponent.
mod - the modulus.
Returns:
a new BigInteger containing the result

negate

public BigInteger negate()
Create a BigInteger with - this value. x.negate() + x = 0
Returns:
a new BigInteger with the negaitve value of this.