你会如何反转这段代码的作用?

时间:2017-01-21 22:10:42

标签: java eclipse encryption

以下是我对加密类的代码:

String encrypt;
String message;
String alpha;
String eMessage;
int index;
Key keyObject;

public String Encrypt(){

        String[] alphabet = {
                "a" , "b" , "c" , "d" , "e" , "f" , "g" , "h" , "i" , "j" , "k" , "l" , "m" , 
                "n" , "o" , "p" , "q" , "r" , "s" , "t" , "u" , "v" , "w" , "x" , "y" , "z"

            };

        StringBuilder sbAlphabet = new StringBuilder();
        StringBuilder sbEncrypt = new StringBuilder();
        for (int i = 0; i <= 25; i++) {
            sbAlphabet.append(alphabet[i]);
        }
        alpha = sbAlphabet.toString();
        message = message.toLowerCase();
        for(int i = 0; i < message.length(); i++) {
            index = alpha.indexOf(message.charAt(i));
            sbEncrypt.append(keyObject.key.charAt(index));
        }
        return sbEncrypt.toString();
    }
}

现在,此代码遍历字母表字符串,然后将用户输入的消息加密为来自不同类中随机生成的键的字符串。我想弄清楚的是,我将如何做到与此相反?如果我想解密消息而不是加密消息,(如果用户输入编码消息然后输入用于加密它的相同密钥),我希望它显示已解码的用户输入。我很确定这样做的代码就像这个代码,除了反转。有谁知道怎么做?

0 个答案:

没有答案