0
각 변수에 대해 암호화 된 메시지를 가져올 값을 지정하고 있습니다. 모두 테스트 용으로 하드 코딩되어 있습니다.RSA 암호화 - 메시지를 암호화하려고하면 잘못된 값이 반환됩니다.
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;
}
Btw : 결과의 첫 번째 값은 538이 아니라 1039입니다. – LostAvatar