Take the 2-minute tour ×
Cryptography Stack Exchange is a question and answer site for software developers, mathematicians and others interested in cryptography. It's 100% free, no registration required.

I was given a ciphertext file which was encrypted using DES in ECB mode. It is known that the plainttext that was encrypted has the following form:

  • Each line of text consists of a payroll followed by a name (no spaces):
    • 32 characters for the name;
    • 8 characters for the pay amount;
    • 1 newline.

An example plaintext file would be:


and it was encrypted using this command (of course the key was not given, for obvious reasons):

openssl enc -e -des-ecb -nosalt -in plaintext.txt -out ciphertext.enc

The ciphertext file is of size 288 bytes since there are 6 newline ('\n') characters and DES encrypts in 64 bit blocks it's easy to tell that there are 7 entries in this payroll list.

The Objective: exchange the first line with the last.

If all the entries were on one line with no spaces this would be an easy task as DES in ECB mode you can move around the 64 bit blocks without being detected. All I would do is take the first 40 bytes and exchange them with the last 40 bytes. However since there is a '\n' character at the end of every line this approach does not work. I feel a bit stuck. All I'm looking for is a point in the right direction.

share|improve this question

migrated from security.stackexchange.com Oct 2 '13 at 22:24

This question came from our site for Information security professionals.

This is a security specific topic certainly, but code golf type questions or questions about breaking specific systems or working with a specific ciphertext are indeed off topic here. It might be a better fit at the Programming Puzzles site. –  Xander Oct 2 '13 at 21:37
@Xander I'll post it there. Would the best practice be to delete this post? –  user31478 Oct 2 '13 at 21:53
@Xander This isn't a brain teaser, it's a serious crypto question. It would be on-topic on Cryptography. Please don't repost, I've flagged for migration. –  Gilles Oct 2 '13 at 22:19
Can you tell me the context where you ran into this? What makes you think it is possible to exchange the first line with the last? Why are you so set on that specific goal? That seems awfully specific (as opposed to, say, swapping some pair of entries of the attacker's choice). I assume you know that you can swap any pair of ciphertext blocks, and the corresponding plaintext blocks will be swapped? So if you can find a pair of blocks that, when swapped, leaves the format of the plaintext undisturbed (and such that the exchange is favorable to the attacker), that's a valid attack. –  D.W. Oct 3 '13 at 5:14
@D.W. This is an specific exercise. I understand that you can swap ciphertext blocks and the associated plaintext blocks will also be swapped accordingly. However, my issue is that I want to swap the last and first lines. There are 40 bytes in the first line (each line) so that's 5 encrypted blocks followed by a newline character which would be included in the next block? wouldn't that make it so i cant just select the last line on it's own? the first chunk would include some of that last lines plaintext as well? and doesn't the last chunk of the last line have padding bits that can't bemoved? –  user31478 Oct 3 '13 at 5:40
show 3 more comments

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.