Seb*_*ner -1 java loops while-loop
我是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";
}
Run Code Online (Sandbox Code Playgroud)
这是我的代码,解码器(); 方法工作得很好.如果我尝试输入一个合法的密码,问题是,外部while循环只执行一次(发现超出打印语句).单词文件也很大,84000+单词.