Score:1

Getting the plaintext encrypting the ciphertext

cn flag

Context: an encryption game from overthewire (the link to it: https://overthewire.org/wargames/krypton/krypton6.html, also good for more info) where given the ciphertext, one must obtain the plaintext.

On this level, we have access to a binary that encrypts any file by stream cipher, using a key from a file we do not have access (keyfile.dat) and a random number. We also have a hint: 8 bit LFSR.

My question is the following. Why can't I get back the plaintext encrypting the ciphertext?

My two assumptions for this claim are:

1) We're dealing with stream cipher, so encrypting the ciphertext should always give the plaintext, as long as the keystream is the same in both cases, what leads me to the second point;

2) I tried to encrypt two different files but with the same content (text) and the encrypted output in both cases was the same, so the keystream must be equal.

I know I'm wrong, as encrypting the ciphertext doesn't give me the plaintext, but rather some non-sense-random-even-more-encrypted file. Can you help me understand what's wrong with my reasoning?

Thanks in advance for any help.

Score:1
ng flag

In a stream cipher, encrypting the ciphertext should always give the plaintext

That's true for the appropriate definition of "ciphertext", which implies it is the same size as the plaintext; and the same Initialisation Vector (the "random number" I guess, hereafter IV) is used.

I suspect the experiment that attempts encrypting the ciphertext again actually encrypts the output of the encryption program, rather than the ciphertext as defined above. The output of the encryption program must somewhat include the ciphertext, but there are common practices that may explain why the experience attempted fails, including

  • The IV is typically included in the output of the encryption, to facilitate decryption. The simplest is it is at start, and the actual ciphertext follows.
  • The ciphertext might be reencoded, e.g. using Base64, headers/trailers..

Next actions could be comparing input and output size for the encryption binary, trying to locate the IV and actual ciphertext, and redoing the experiment using only the actual ciphertext as input of the re-encryption.

Alternatively, another property of a stream cipher can help: encrypt two plaintext that differ by their first byte, under the same IV, and compare the ciphertexts. The location of the difference tells where the actual ciphertext starts.

arpg avatar
cn flag
_I suspect the experiment that attempts encrypting the ciphertext again actually encrypts the output of the encryption program, rather than the ciphertext as defined above._ - I'm not sure if I understood this, could you explain a little better?
fgrieu avatar
ng flag
@arpg: it could be the encryption program outputs more than the ciphertext. Like IV and ciphertext. So that you don't re-encrypt just the ciphertext, and thus don't get the expected result.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.