Blowfish算法加密时不产生输出

时间:2018-01-06 22:11:36

标签: java algorithm encryption blowfish block-cipher

我正在尝试编写Blowfish加密算法的源代码。

尝试打印出加密邮件时,我得到一个空白输出。

例如:

npm install -verbose --save pinkie-promise@2.0.1

以下是我的加密功能的代码:

Blowfish test = new Blowfish();
String message = test.encrypt("test", "password");
System.out.println("Output = " + message);

Output = 

以下是加密功能

中调用的函数
public String encrypt(String input, String key) //Encrypting a string with a input key
{
    init(key);
    StringBuffer binaryInput = new StringBuffer(StringToBit(input));
    while (binaryInput.length() % 64 != 0) {
        binaryInput.insert(0, "0");
    }
    String[] blocks = new String[binaryInput.length() % 64];

    for (int i = 0; i < blocks.length; i++) {
        blocks[i] = binaryInput.substring(0, 64);
        binaryInput.delete(0, 64);
    }

    StringBuffer enc = new StringBuffer();
    int L;
    int R;
    for (int i = 0; i < blocks.length; i++) {
        L = Integer.parseInt(blocks[i].substring(0, 32), 2);
        R = Integer.parseInt(blocks[1].substring(33, 64), 2);
        en(L, R);
        enc.append(Integer.toHexString(L));
        enc.append(Integer.toHexString(R));
        //enc.append(" "); //Breaks every 64-Bits
    }
    reset();
    return (enc.toString());
}

Here is the link to my GitHub Project if you would like view the entire Blowfish class.

1 个答案:

答案 0 :(得分:0)

看起来像这一行

String[] blocks = new String[binaryInput.length() % 64];

应该是

String[] blocks = new String[binaryInput.length() / 64];