gpt4 book ai didi

java - RSA 加密 - 尝试加密消息返回错误值

转载 作者:行者123 更新时间:2023-12-01 13:57:54 25 4
gpt4 key购买 nike

我为每个变量输入值以获取加密消息。所有这些都被硬编码以用于测试目的。

当它应该返回 538 1729 1328 1328 2146 时,它会返回值 ??????。我是否输入了错误的内容?这是我的代码遇到的唯一问题。

public static void main(String[] args){
int p = 61;
int q = 37;
int pq = p * q;
int phiPQ = (p - 1) * (q - 1);
int e = 7;
int d = 1543;
String message = encryptMsg("hello", pq, e);
System.out.println(message);
}

public static String encryptMsg(String msg, int pq, int e){
BigInteger bE = new BigInteger(Integer.toString(e));
BigInteger bPQ = new BigInteger(Integer.toString(pq));
String encryptedMsg = "";
for(int i = 0; i < msg.length(); i++){
BigInteger m = new BigInteger(Integer.toString(msg.charAt(i)));
BigInteger bC = m.modPow(bE, bPQ);
encryptedMsg += " " + (char)bC.intValue();
}
return encryptedMsg;
}

最佳答案

我想你可能想要

encryptedMsg +=" " + bC.toString();

目前您正在将整数转换为字符,因此我猜想返回unicode,而您似乎期望的是整数作为字符串。

关于java - RSA 加密 - 尝试加密消息返回错误值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19526855/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com