Java 解密加密的文本文件

Java 解密加密的文本文件,java,encryption,Java,Encryption,我有一种解密方法,它应该打开一个带有加密文本的测试文件,然后读取并解密我从输入文件中读入的每一行文本。该文本文件名为summary.txt。 我可以在只输入单个字符的情况下使用该方法,但在打开.txt文件并逐行解密的情况下无法使用该方法 卸货方法: public static String cipherDecipherString(String text) { // These are global. Put here for space saving private static fin

我有一种解密方法,它应该打开一个带有加密文本的测试文件,然后读取并解密我从输入文件中读入的每一行文本。该文本文件名为summary.txt。 我可以在只输入单个字符的情况下使用该方法,但在打开.txt文件并逐行解密的情况下无法使用该方法

卸货方法:

public static String cipherDecipherString(String text)

{
 // These are global. Put here for space saving
 private static final String crypt1 = "cipherabdfgjk";
 private static final String crypt2 = "lmnoqstuvwxyz";

    // declare variables
    int i, j;
    boolean found = false;
    String temp="" ; // empty String to hold converted text
    readFile();
    for (i = 0; i < text.length(); i++) // look at every chracter in text
    {
        found = false;
        if ((j = crypt1.indexOf(text.charAt(i))) > -1) // is char in crypt1?
        {           
            found = true; // yes!
            temp = temp + crypt2.charAt(j); // add the cipher character to temp
        }
        else if ((j = crypt2.indexOf(text.charAt(i))) > -1) // and so on
        {
            found = true;
            temp = temp + crypt1.charAt(j);
        }
        if (! found) // to deal with cases where char is NOT in crypt2 or 2
        {
            temp = temp + text.charAt(i); // just copy across the character
        }
    }
    return temp;
}

现在我想我可以调用我的readFile方法,然后进入解密代码,它让它在文件中工作,但我根本无法让它工作。

在readFile中,你没有对你读的行做任何事情,你没有在任何地方调用密码解密字符串

编辑:您可以将文件中的所有行添加到数组中,并从函数返回数组。然后遍历该数组并逐行解密

将readFile返回类型更改为ArrayList

ArrayList<String> textLines = new ArrayList<>();
while(nextLine != null) {
    textLines.add(nextLine);
    nextLine = bufferedReader.readLine();
}

return textLines;
然后在密码解密字符串中调用readFile

ArrayList<String> textLines = readFile();

反过来说,我需要它。我想用密码解密字符串调用readFile。我试过了,但我不能让它正常工作。
ArrayList<String> textLines = readFile();