We have a key representing an SHA-256 hash in HEX, and we have the key in AES-ECB. We also have a file with plaintext to cipher messages that were encrypted with our key. How could we find this key?


The above is the flag encrypted in AES-ECB, we know that the flag is a hex representation of an SHA-256 hash:

79621ca63d052e64 --> ca5b6fdb77e3b1ec39b6c4e1a4b69ba5

55191c3c4eeb107e --> ded63de07b250d83f842d7bc860db40c

We have a whole list with plaintext that was encrypted with our key (flag).

  • $\begingroup$ You mean, you have the hash of the encryption key? With this knowledge, no! May be you have limited keyspace that you can test it with the hash value? $\endgroup$
    – kelalaka
    Feb 15 '21 at 16:18

ECB is weak because a given 128 bit input block maps to the same encrypted output block. The only thing you can do is look for matches between blocks of the encrypted flag and outputs in the known plaintext ciphertext pairs file.

Essentially for each 128 bit chunk of ASCII text in the flag E(plaintext)=ciphertext. The known plaintext ciphertext pair file is essentially a big table of E(plaintext)=ciphertext for a bunch of plaintext ciphertext pairs. If you find one of the encrypted flag blocks in that file:


You have the decryption for that block. Just ctrl-f for these values and assemble the decrypted chunks to find the unencrypted flag. They have to be there for the CTF to be solveable.


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