我正在尝试将xor操作的结果存储到字符串数组中。如图所示运行代码时,它可以打印出值。
int[] randnumbs = new int[0];
randnumbs = streamGen(plaintext.length());
String plaintextnumb;
String encryption;
int[] answer = new int[0];
int count = 0;
while(true) {
plaintextnumb = plaintext.substring(count,count + 2);
int numbfromfile = Integer.valueOf(plaintextnumb,16);
int xored = numbfromfile ^ randnumbs[count];
encryption = Integer.toHexString(xored);
System.out.print(encryption + " ");
if(count == (plaintext.length() / 2) - 1) {
break;
}else {
count++;
}
}
结果:
af a0 52 b1 fb 0 a6 75
当我将变量“ encryption”更改为String数组时,我的代码可以运行,但是当到达“ encryption [count] = Integer.toHexString(xored);”位置时,接缝将停止运行。我以前从未遇到过这个问题。当我运行程序时,没有错误显示,它只是显示一个空控制台。我还在此代码行之前和之后插入了printout语句,并且只能在代码行之前而不是之后看到打印输出。对此原因的任何解释将不胜感激!
int[] randnumbs = new int[0];
randnumbs = streamGen(plaintext.length());
String plaintextnumb;
String[] encryption = new String[0];
int[] answer = new int[0];
int count = 0;
while(true) {
plaintextnumb = plaintext.substring(count,16);
int xored = numbfromfile ^ randnumbs[count];
encryption[count] = Integer.toHexString(xored);
System.out.print(encryption[count] + " ");
if(count == (plaintext.length() / 2) - 1) {
break;
}else {
count++;
}
}