我有这种方法,它需要一个 BigInteger,生成另一个 BigInteger(通过 rsa 算法),然后将其转换为二进制,然后将其分解为 8 个块,在其中我得到该二进制字符串的 ascii 值。
所有这些都有效
但是我无法从每个二进制字符串中获取 ascii 字符并从中创建一个新字符串。我试图使用内置的 concat 方法,但它似乎不起作用!
public static String Decrypt( BigInteger ct, BigInteger d, BigInteger mod ){
String pt = null;
BigInteger message = ct.modPow(d, mod); //the decrypted message M but still in BigInteger form
String plaintext = message.toString(2);
if( plaintext.length() % 8 != 0 ){
plaintext = "00000000".substring( plaintext.length() % 8 ) + plaintext;
}
String c;
int charCode = 0;
for( int i = (plaintext.length()/8) - 1 ; i >= 0; i--){
charCode = Integer.parseInt((plaintext.substring(i*8, (i*8)+8)) , 2) ;
c = new Character( (char) charCode).toString();
System.out.print(c); // here is where i need something like pt.concat(c) or something like that, I dont really want it printed
} // i just want all of these chars to be put into the string pt
System.out.println();
return pt;
}
正如您在评论中看到的那样,这就是我所说的,我的意思是通过查看 concat 的 API,我所做的似乎是正确的,但它就是行不通!
谢谢你能解释/显示什么是错的!