Class BigIntegers


  • public final class BigIntegers
    extends java.lang.Object
    BigInteger utilities.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.math.BigInteger ONE  
      static java.math.BigInteger TWO  
      static java.math.BigInteger ZERO  
    • Constructor Summary

      Constructors 
      Constructor Description
      BigIntegers()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static byte[] asUnsignedByteArray​(int length, java.math.BigInteger value)
      Return the passed in value as an unsigned byte array of the specified length, padded with leading zeros as necessary..
      static byte[] asUnsignedByteArray​(java.math.BigInteger value)
      Return the passed in value as an unsigned byte array.
      static void asUnsignedByteArray​(java.math.BigInteger value, byte[] buf, int off, int len)
      Write the passed in value as unsigned bytes to the specified buffer range, padded with leading zeros as necessary.
      static java.math.BigInteger createRandomBigInteger​(int bitLength, java.security.SecureRandom random)
      Return a positive BigInteger in the range of 0 to 2**bitLength - 1.
      static java.math.BigInteger createRandomInRange​(java.math.BigInteger min, java.math.BigInteger max, java.security.SecureRandom random)
      Return a random BigInteger not less than 'min' and not greater than 'max'
      static java.math.BigInteger createRandomPrime​(int bitLength, int certainty, java.security.SecureRandom random)
      Return a prime number candidate of the specified bit length.
      static java.math.BigInteger fromUnsignedByteArray​(byte[] buf)  
      static java.math.BigInteger fromUnsignedByteArray​(byte[] buf, int off, int length)  
      static int getUnsignedByteLength​(java.math.BigInteger n)  
      static int intValueExact​(java.math.BigInteger x)  
      static long longValueExact​(java.math.BigInteger x)  
      static java.math.BigInteger modOddInverse​(java.math.BigInteger M, java.math.BigInteger X)  
      static java.math.BigInteger modOddInverseVar​(java.math.BigInteger M, java.math.BigInteger X)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • ZERO

        public static final java.math.BigInteger ZERO
      • ONE

        public static final java.math.BigInteger ONE
      • TWO

        public static final java.math.BigInteger TWO
    • Constructor Detail

      • BigIntegers

        public BigIntegers()
    • Method Detail

      • asUnsignedByteArray

        public static byte[] asUnsignedByteArray​(java.math.BigInteger value)
        Return the passed in value as an unsigned byte array.
        Parameters:
        value - the value to be converted.
        Returns:
        a byte array without a leading zero byte if present in the signed encoding.
      • asUnsignedByteArray

        public static byte[] asUnsignedByteArray​(int length,
                                                 java.math.BigInteger value)
        Return the passed in value as an unsigned byte array of the specified length, padded with leading zeros as necessary..
        Parameters:
        length - the fixed length of the result
        value - the value to be converted.
        Returns:
        a byte array padded to a fixed length with leading zeros.
      • asUnsignedByteArray

        public static void asUnsignedByteArray​(java.math.BigInteger value,
                                               byte[] buf,
                                               int off,
                                               int len)
        Write the passed in value as unsigned bytes to the specified buffer range, padded with leading zeros as necessary.
        Parameters:
        value - the value to be converted.
        buf - the buffer to which the value is written.
        off - the start offset in array buf at which the data is written.
        len - the fixed length of data written (possibly padded with leading zeros).
      • createRandomInRange

        public static java.math.BigInteger createRandomInRange​(java.math.BigInteger min,
                                                               java.math.BigInteger max,
                                                               java.security.SecureRandom random)
        Return a random BigInteger not less than 'min' and not greater than 'max'
        Parameters:
        min - the least value that may be generated
        max - the greatest value that may be generated
        random - the source of randomness
        Returns:
        a random BigInteger value in the range [min,max]
      • fromUnsignedByteArray

        public static java.math.BigInteger fromUnsignedByteArray​(byte[] buf)
      • fromUnsignedByteArray

        public static java.math.BigInteger fromUnsignedByteArray​(byte[] buf,
                                                                 int off,
                                                                 int length)
      • intValueExact

        public static int intValueExact​(java.math.BigInteger x)
      • longValueExact

        public static long longValueExact​(java.math.BigInteger x)
      • modOddInverse

        public static java.math.BigInteger modOddInverse​(java.math.BigInteger M,
                                                         java.math.BigInteger X)
      • modOddInverseVar

        public static java.math.BigInteger modOddInverseVar​(java.math.BigInteger M,
                                                            java.math.BigInteger X)
      • getUnsignedByteLength

        public static int getUnsignedByteLength​(java.math.BigInteger n)
      • createRandomBigInteger

        public static java.math.BigInteger createRandomBigInteger​(int bitLength,
                                                                  java.security.SecureRandom random)
        Return a positive BigInteger in the range of 0 to 2**bitLength - 1.
        Parameters:
        bitLength - maximum bit length for the generated BigInteger.
        random - a source of randomness.
        Returns:
        a positive BigInteger
      • createRandomPrime

        public static java.math.BigInteger createRandomPrime​(int bitLength,
                                                             int certainty,
                                                             java.security.SecureRandom random)
        Return a prime number candidate of the specified bit length.
        Parameters:
        bitLength - bit length for the generated BigInteger.
        random - a source of randomness.
        Returns:
        a positive BigInteger of numBits length