List of utility methods to do BigInteger is Prime
BigInteger | calculateMPrime(BigInteger n, byte[] message) Method taken (renamed) from SpongyCastle ECDSASigner class. if (n.bitLength() > message.length * 8) { return new BigInteger(1, message); } else { int messageBitLength = message.length * 8; BigInteger trunc = new BigInteger(1, message); if (messageBitLength - n.bitLength() > 0) { trunc = trunc.shiftRight(messageBitLength - n.bitLength()); return trunc; |
BigInteger | fnvHash(final byte[] data, final BigInteger fnvOffs, final BigInteger fnvPrime, final BigInteger mod) fnv Hash BigInteger hash = fnvOffs; for (final byte next : data) { final BigInteger bigIntValue = BigInteger.valueOf(next & 0xff); hash = hash.xor(bigIntValue); hash = hash.multiply(fnvPrime).mod(mod); return hash; |
boolean | hasSqrtModPrime(BigInteger r, BigInteger p) has Sqrt Mod Prime BigInteger two = new BigInteger("2"); return r.modPow(p.subtract(BigInteger.ONE).divide(two), p).equals(BigInteger.ONE); |
boolean | isBigPrime(BigInteger number) is Big Prime BigInteger random = createRandomInteger(number, new Random()); return testPrime(number, random); |
boolean | isCoprime(BigInteger a, BigInteger b) Returns true if A and B are coprime. return a.gcd(b).equals(BigInteger.ONE);
|
boolean | isFermatPrime(BigInteger f) Fermat number deterministic primality test (Fermat number is an integer in the form Fn = 22^n + 1). if (f.signum() <= 0) return false; if (f.bitLength() <= 31) { switch (f.intValue()) { case 3: case 5: case 17: case 257: ... |
boolean | isPrime(BigInteger value) Checks if value is a prime number,
if (value.signum() < 0) { throw new IllegalArgumentException("Only positive values permitted."); BigInteger two = new BigInteger("2"); if (value.compareTo(two) < 0) { return false; if (value.equals(two)) { ... |
Boolean | primeProcessPart(BigInteger from) prime Process Part return null;
|
BigInteger | sqrtModPrime(BigInteger rSquare, BigInteger p) sqrt Mod Prime BigInteger two = new BigInteger("2"); BigInteger z = two; while (hasSqrtModPrime(z, p)) { z = z.add(BigInteger.ONE); if (!hasSqrtModPrime(rSquare, p)) { throw new UnknownError("r has no square root"); } else { ... |