Difference between BigInteger.probablePrime() and other primality algorithms in java

前端 未结 2 1669
[愿得一人]
[愿得一人] 2020-12-19 10:36

I am implementing an RSA encryption program using Java. Right now I am using BigInteger.probablePrime(1024, rnd) to get prime numbers. Here rnd

2条回答
  •  不思量自难忘°
    2020-12-19 11:19

    The Java source code is available for download, so you can look at it yourself. Here is the code for BigInteger.probablePrime(int, Random):

    public static BigInteger probablePrime(int bitLength, Random rnd) {
    
        if (bitLength < 2)
            throw new ArithmeticException("bitLength < 2");
    
        // The cutoff of 95 was chosen empirically for best performance
    
        return (bitLength < SMALL_PRIME_THRESHOLD ?
                smallPrime(bitLength, DEFAULT_PRIME_CERTAINTY, rnd) :
                largePrime(bitLength, DEFAULT_PRIME_CERTAINTY, rnd));
    }
    

    The actual tests are contained in the smallPrime() and largePrime() methods, which follow directly in the source code.

提交回复
热议问题