I know there are 4 known weak keys, their value and that double encryption using one of the weak keys should give back the plain text.

I implemented this in OpenSSL. I have a plain text $m$ in a file plain.txt and compute $y = DES_k(m)$ where $k$ is a weak key. Then I compute $y' = DES_k(y)$. Instead of getting $m$ I get only a portion of it and the rest is part of $y$.

Why is this happening?


If you don't get the expected result, then you are doing it wrong; most probably, use wrong mode of operation and/or wrong padding. You can get the expected result with openssl as

openssl enc -e -des-ecb -in plain.txt -out cipher1.txt -nopad -K 0101010101010101 -iv 0
openssl enc -e -des-ecb -in cipher1.txt -out cipher2.txt -nopad -K 0101010101010101 -iv 0

plain.txt file size should be multiple of 8 (8 bytes is DES block size), and plain.txt and cipher2.txt files should be identical.

  • $\begingroup$ I'm almost there. I get an error that says "Data not multiple of block length", but when I look at cipher2.txt, more of the plaintext is there, but not all of it. My plaintext file has 19 characters (includes spaces). Is this related to the padding? How do I force the data to be a multiple of the block length? $\endgroup$
    – planejane
    Sep 18 '16 at 16:29
  • $\begingroup$ Eureka. The mode should be ofb. Off to research why. Hints welcomed. ;) Thank you! $\endgroup$
    – planejane
    Sep 18 '16 at 16:51
  • 2
    $\begingroup$ @planejane Eureaka is wrong. You should use ECB mode without padding (-nopad option), and plaintext file size should be multiple of 8 (8 bytes is DES block size); OFB mode decryption is the same operation as encryption, so OFB double encryption with the same key is in fact encryption+decryption, and it works with any key, not with a weak key only. $\endgroup$
    – kludg
    Sep 18 '16 at 17:06
  • 1
    $\begingroup$ file size should be multiple of 8, so add some characters (dot, spaces, anything you like) to the end of file to make the file size multiple of 8. $\endgroup$
    – kludg
    Sep 18 '16 at 17:15
  • 1
    $\begingroup$ @planejane: that handling is padding. You can see it at work: specify -e -des-ecb for encryption and -e -des-ecb -nopad for decryption; then examine the deciphered plaintext with something that can view arbitrary bytes, like hexdump. $\endgroup$
    – fgrieu
    Sep 19 '16 at 3:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.