我试图破译Vigenere_Cipher,当我输入BEXR TKGKTRQFARI时,输出是JAVAPROGRAMMING,但是我想像JAVA PROGRAMMING那样放置空格。
我的密码
public static String VigenereDecipher(String text) {
String keyword = "SECRET";
String decipheredText = "";
text = text.toUpperCase();
for (int i = 0, j = 0; i < text.length(); i++) {
char c = text.charAt(i);
if (c < 'A' || c > 'Z') continue;
decipheredText += (char)((c - keyword.charAt(j) + 26) % 26 + 'A');
j = ++j % keyword.length();
}
return decipheredText;
}发布于 2018-11-29 15:35:33
你明显忽略了空格。您只需添加以下一行:
if (c == ' ') {
decipheredText += ' ';
}一定要把它放在这一行之前:
if (c < 'A' || c > 'Z') continue;发布于 2018-11-29 15:41:31
你忽略了这个空间。在检查字符范围'A‘到'Z’时检查空格,并将其作为空格添加到decipheredText中,因为您不希望空间被视为另一个字符。
https://stackoverflow.com/questions/53542147
复制相似问题