BigInteger.probablePrime() 与 java 中其他素性算法的区别

发布于 2024-12-24 22:13:23 字数 334 浏览 2 评论 0原文

我正在使用 Java 实现 RSA 加密程序。现在我正在使用 BigInteger.probablePrime(1024, rnd) 来获取素数。这里 rnd 是由 Random rnd = new Random() 生成的随机数。 我需要测试各种加密速度。

我的问题是:

  1. BigInteger.probablePrime(1024, rnd) 使用什么算法?

  2. 上述算法与其他算法(如 Rabin-Miller、Fermats、Lucas-Lehmer)有何区别?

谢谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

孤独难免 2024-12-31 22:13:23

BigInteger 的可能素数方法使用 Miller-Rabin 和 Lucas-Lehmer 算法来测试素数。

查看内部方法 BigInteger.primeToCertainty< /a>.

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

See the internal method BigInteger.primeToCertainty.

冷月断魂刀 2024-12-31 22:13:23

Java源代码已经可以下载了,大家可以自己看一下。
以下是 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));
}

实际测试包含在 smallPrime()largePrime() 方法中,直接在源代码中。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文