我对 Java 很陌生,目前,我正在研究 Vigenere 密码解密/加密。我已经使用已知密钥进行了解密和加密,我现在唯一想做的就是字典攻击。为此,算法从文本文件中取出一行并将其用作解密消息的密钥,然后获取解密后的消息并再次将其与字典进行交叉引用(如果密钥生成了合法的单词,它将使用该密钥解密消息的其余部分)。
public static String decoderNoKey(String msg, Scanner words) {
Scanner words2 = words;
while (words.hasNextLine()) {
String dicStr = words.nextLine();
String result = decoder(msg, dicStr);
while (words2.hasNextLine()) {
String meta = words2.nextLine();
if(result.equalsIgnoreCase(meta)) {
System.out.println("Found a matching message: " + result);
System.out.println("This is the corresponding key: " + dicStr);
return meta;
}
}
}
return "There was no matching word";
}
这是我的代码,解码器();方法工作得很好。如果我尝试输入合法密码,问题是,外部 while 循环仅执行一次(发现超出打印语句)。单词文件也很大,84000 多个单词。
慕婉清6462132
相关分类