1
我想实现RSA algorithm,但由于某种原因,我的代码下面并没有产生正确的结果(注意只显示了相关的代码)。实施RSA算法的小故障
BigInteger n = p.multiply(q);
BigInteger totient = (p.subtract(BigInteger.ONE)).multiply(q.subtract(BigInteger.ONE));
Random rand = new Random();
BigInteger e;
do
{
e = new BigInteger(totient.bitLength(), rand);
} while ((e.compareTo(BigInteger.ONE) <= 0 || e.compareTo(totient) >= 0)
&& !((e.gcd(totient)).equals(BigInteger.ONE)));
BigInteger d = (BigInteger.ONE.divide(e)).mod(totient);
使用127和131作为主号码输入
样本输出(注意,16637是正确的,但7683和0都没有):
Public Key: (16637,7683)
Private Key: (16637,0)
感谢您的帮助!
向我们展示一些输出 – Woot4Moo 2010-10-30 01:26:12
添加了示例输出。 – 2010-10-30 01:28:18
我不确定,但BigInteger d =(BigInteger.ONE.divide(e)).mod(totient);有99%的可能性。 () – Jonathan 2010-10-30 01:41:16