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