我一直在使用polybius方块对我的程序进行加密。虽然我已经得到了这个工作,但需要说的是,当一个单词被加密时,它需要为不止一次出现的字母选择替代数字。JAVA - 使用数组进行加密
例如'E'在加密时需要用15或61表示,并且它必须交替。我正在努力寻找解决方案,任何反馈都会很棒。
这里是目前我的源代码:
public class Encryption {
private static char polybiusSquare[][] = { { 'A', 'B', 'C', 'D', 'E', 'F' },
{ 'G', 'H', 'I', 'K', 'L', 'M' },
{ 'N', 'O', 'P', 'Q', 'R', 'S' },
{ 'T', 'U', 'V', 'W', 'X', 'Y' },
{ 'Z', 'E', 'T', 'A', 'O', 'N' },
{ 'E', 'T', 'A', 'O', 'J', ' ' } };
public static String encryptMessage(String message) {
String encipheredMessage = "";
for (int x = 0; x < message.length(); x++) {
encipheredMessage = encipheredMessage + encryptCharacter(message.charAt(x));
}
return encipheredMessage;
}
public static String encryptCharacter(char currentChar) {
String returnGridRef = "";
for (int x = 0; x < 6; x++) {
for (int y = 0; y < 6; y++) {
if (currentChar == polybiusSquare[x][y]) {
returnGridRef = Integer.toString(x + 1) + Integer.toString(y + 1);
}
}
}
if (returnGridRef.equals(""))
return "00";
else
return returnGridRef;
}
问题和代码的质量比我在几天内从新用户看到的要好得多。 – MikeC