List of utility methods to do BigInteger Calculate
String | numberToShortString(BigInteger number) Returns a string representing the shortened numeric value. int scale; String suffix; BigDecimal work; if (number.compareTo(DISPLAY_1P) >= 0) { scale = 15; suffix = "P"; } else if (number.compareTo(DISPLAY_1T) >= 0) { scale = 12; ... |
BigInteger | order(BigInteger a, BigInteger p, BigInteger f[], BigInteger e[]) Find the order of a in Z_p where p-1 has the factors in array f each with the corresponding exponent in array e BigInteger order = p.subtract(BigInteger.ONE); for (int k = 0; k < f.length; k++) { int _e = e[k].intValue(); for (int i = 0; i < _e; i++) { BigInteger exponent = order.divide(f[k]); BigInteger test = a.modPow(exponent, p); if (BigInteger.ONE.equals(test)) { order = exponent; ... |
BigInteger | parseBigInteger(String s, BigInteger defaultValue) parse Big Integer String ch = getNumberChars(s); if (ch == null) { return defaultValue; return new BigInteger(ch); |
long | parseBinaryBigInteger(final byte[] buffer, final int offset, final int length, final boolean negative) parse Binary Big Integer byte[] remainder = new byte[length - 1]; System.arraycopy(buffer, offset + 1, remainder, 0, length - 1); BigInteger val = new BigInteger(remainder); if (negative) { val = val.add(BigInteger.valueOf(-1)).not(); if (val.bitLength() > 63) { throw new IllegalArgumentException("At offset " + offset + ", " + length + " byte binary number" ... |
BigInteger | parseScaledNonNegativeBigInteger(String str) parse Scaled Non Negative Big Integer str = adjustForSign(str); int radix = computeRadix(str); str = adjustForRadix(str); long scale = computeScale(str); str = adjustForScale(str, scale); BigInteger value = new BigInteger(str, radix); if (scale != 1) { value = value.multiply(new BigInteger(String.valueOf(scale))); ... |
BigInteger | product(final BigInteger min, final BigInteger max) Compute the product of all integers in the range [min,max]. BigInteger ret = BigInteger.ONE; for (BigInteger i = min; i.compareTo(max) <= 0; i = i.add(BigInteger.ONE)) { ret = ret.multiply(i); return ret; |
BigInteger | randomFromZn(BigInteger n, Random rand) random From Zn BigInteger result; do { result = new BigInteger(n.bitLength(), rand); } while (result.compareTo(n) != -1); return result; |
BigInteger[] | removeDuplicates(final BigInteger... values) Removes duplicate values from a BigInteger array
if (values == null) { throw new IllegalArgumentException(); final HashSet<BigInteger> hashSet = new HashSet<BigInteger>(Arrays.asList(values)); return hashSet.toArray(new BigInteger[hashSet.size()]); |
byte[] | renderBigInteger(final BigInteger bint) Return an 8 byte array from a BigInteger value. final byte[] retval = new byte[8]; byte[] arry = bint.toByteArray(); if (arry.length > retval.length) System.arraycopy(arry, arry.length - retval.length, retval, 0, retval.length); else if (arry.length < retval.length) System.arraycopy(arry, 0, retval, retval.length - arry.length, arry.length); else System.arraycopy(arry, 0, retval, 0, retval.length); ... |
BigInteger | retrieveBigInteger(final byte[] buf, final int offset) Get an unsigned integer (U64) from 8 bytes in a byte[] buffer. final byte[] chunk = new byte[8]; System.arraycopy(buf, offset, chunk, 0, 8); return new BigInteger(1, chunk); |