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

Deadly 提交于 2019-11-28 04:05:38

问题


I am implementing an RSA encryption program using Java. Right now I am using BigInteger.probablePrime(1024, rnd) to get prime numbers. Here rnd is a random number generated by Random rnd = new Random() . I need to test various speeds of encryption.

My questions are:

  1. what algorithm does the BigInteger.probablePrime(1024, rnd) use?

  2. what is the difference between the algorithm above and other algorithms: like Rabin-Miller, Fermats, Lucas-Lehmer?

Thank you.


回答1:


BigInteger's probable prime methods use both the Miller-Rabin and Lucas-Lehmer algorithms to test primality.

See the internal method BigInteger.primeToCertainty.




回答2:


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.



来源:https://stackoverflow.com/questions/8744085/difference-between-biginteger-probableprime-and-other-primality-algorithms-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!