1

使用java中给出的DES解决加密和解密问题。我已经想出了如何很容易地加密和解密,但现在我卡住了。对于当前的问题,我有明文和对应的密文(格式为 8 个十六进制对,例如:A5 33 1F ..),但我也有密钥的前 4 个十六进制位。我并不是真的要代码,而是更多地想知道我将如何解决这个问题!任何事情都会有帮助!这是我的解密代码(只是包含它以表明我正在努力工作:))。多谢你们!

public static void decrypt(){
    Cipher cipher;
    SecretKeySpec key;
    byte [] keyBytes;
    byte [] pt;
    byte [] ct;
    String plaintxt;

    keyBytes = new byte [] {(byte)0xFE, (byte)0xDC, (byte)0xBA, (byte)0x98, (byte)0x76, (byte)0x54, (byte)0x32, (byte)0x10};
    key = new SecretKeySpec(keyBytes, "DES");
    ct = new byte [] {(byte) 0x2C, (byte) 0xE6, (byte) 0xDD, (byte) 0xA4, (byte) 0x98, (byte) 0xCA, (byte) 0xBA, (byte) 0xB9};

    try{
        cipher = Cipher.getInstance("DES/ECB/NoPadding");
        cipher.init(Cipher.DECRYPT_MODE, key);
        pt = cipher.doFinal(ct);
        printByteArray(pt);
        plaintxt = byteToHex(pt);
        hexToAscii(plaintxt);
    }
    catch(Exception e){
        e.printStackTrace();
    }

}
4

1 回答 1

1

蛮力。

枚举它可能是的每个密钥(给定固定字节),直到获得使明文和密文匹配的解密。它将需要编辑:不过,平均 2^37 次尝试,所以不要指望它会很快发生:)

There are some properties of DES that let you crack it faster, but they're very difficult to implement and I doubt you'd be expected to learn them. But if you are interested, http://en.wikipedia.org/wiki/Data_Encryption_Standard#Security_and_cryptanalysis

于 2013-02-10T00:44:59.753 回答