Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.bouncycastle.pqc.math.linearalgebra;
  
FIXME: is this really necessary?!
  
  public final class BigIntUtils
  {

    
Default constructor (private).
 
     private BigIntUtils()
     {
         // empty
     }

    
Checks if two BigInteger arrays contain the same entries

Parameters:
a first BigInteger array
b second BigInteger array
Returns:
true or false
 
     public static boolean equals(BigInteger[] aBigInteger[] b)
     {
         int flag = 0;
 
         if (a.length != b.length)
         {
             return false;
         }
         for (int i = 0; i < a.lengthi++)
         {
             // avoid branches here!
             // problem: compareTo on BigIntegers is not
             // guaranteed constant-time!
             flag |= a[i].compareTo(b[i]);
         }
         return flag == 0;
     }

    
Fill the given BigInteger array with the given value.

Parameters:
array the array
value the value
 
     public static void fill(BigInteger[] arrayBigInteger value)
     {
         for (int i = array.length - 1; i >= 0; i--)
         {
             array[i] = value;
         }
     }

    
Generates a subarray of a given BigInteger array.

Parameters:
input - the input BigInteger array
start - the start index
end - the end index
Returns:
a subarray of input, ranging from start to end
 
     public static BigInteger[] subArray(BigInteger[] inputint startint end)
     {
         BigInteger[] result = new BigInteger[end - start];
         System.arraycopy(inputstartresult, 0, end - start);
         return result;
     }

    
Converts a BigInteger array into an integer array

Parameters:
input - the BigInteger array
Returns:
the integer array
 
     public static int[] toIntArray(BigInteger[] input)
     {
         int[] result = new int[input.length];
         for (int i = 0; i < input.lengthi++)
         {
             result[i] = input[i].intValue();
         }
         return result;
     }

    
Converts a BigInteger array into an integer array, reducing all BigIntegers mod q.

Parameters:
q - the modulus
input - the BigInteger array
Returns:
the integer array
    public static int[] toIntArrayModQ(int qBigInteger[] input)
    {
        BigInteger bq = BigInteger.valueOf(q);
        int[] result = new int[input.length];
        for (int i = 0; i < input.lengthi++)
        {
            result[i] = input[i].mod(bq).intValue();
        }
        return result;
    }

    
Return the value of big as a byte array. Although BigInteger has such a method, it uses an extra bit to indicate the sign of the number. For elliptic curve cryptography, the numbers usually are positive. Thus, this helper method returns a byte array of minimal length, ignoring the sign of the number.

Parameters:
value the BigInteger value to be converted to a byte array
Returns:
the value big as byte array
    public static byte[] toMinimalByteArray(BigInteger value)
    {
        byte[] valBytes = value.toByteArray();
        if ((valBytes.length == 1) || (value.bitLength() & 0x07) != 0)
        {
            return valBytes;
        }
        byte[] result = new byte[value.bitLength() >> 3];
        System.arraycopy(valBytes, 1, result, 0, result.length);
        return result;
    }
New to GrepCode? Check out our FAQ X