在发布我的代码之前,我认为最好首先安排一些事情 .
Goal:
对几个小数字执行非常基本的RSA加密 . 对于那些熟悉RSA加密的人,我已经发布了下面算法使用的值 .
Current RSA numbers/values:
P = 29
Q = 31
N = P * Q
披=((P-1)*(Q-1))
E = 11
My issue:
当我试图解密我的代码时出现问题 . 加密按设计工作 .
Code:
long[] mesg = new long[]{8, 7, 26, 28};
long[] encrypted_mesg = new long[mesg.length];
for(int i=0; i
encrypted_mesg[i]=(long)((Math.pow(mesg[i],E))%N);
System.out.print(encrypted_mesg[i] + " ");
}
System.out.println();
//Decrpyt (not functioning-long to small, Big Integer not working)
for(int j=0; j
BigInteger decrypt = new BigInteger(Math.pow(encryp_mesg[j],D) + "");
System.out.print(decrypt.toString() + " ");
}
最初的问题是D(私人指数)在作为指数应用时,是长期的方式 . 我做了一个快速的谷歌搜索,并决定尝试实施BigInteger . 当我运行该程序时,它会抛出此错误:
Exception in thread "main" java.lang.NumberFormatException: For input string: "Infinity"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:580)
at java.math.BigInteger.(BigInteger.java:461)
at java.math.BigInteger.(BigInteger.java:597)
at RSA_Riddles.main(RSA_Riddles.java:23)**
What I have tried to fix the problem:
说实话,我没有尝试任何事情,因为我知道答案不会计算到无限,但BigInteger认为它确实如此 . 无论如何我可以存储130 ^ 611这样的数字吗?如果是这样,怎么样?
Big Question:
如何存储执行解密所需的值?
提前感谢任何试图帮助我的人!