Search code examples
aes

Can AES generate arbitrary ciphertext by choosing plaintext and key?


All my confusion comes from the following example:

key='c086e08ad8ee0ebe7c2320099cfec9eea9a346a108570a4f6494cfe7c2a30ee1'.decode('hex')
IV='78228d4760a3675aa08d47694f88f639'.decode('hex')
pad=lambda S: S+chr(16-len(S)%16)*(16-len(S)%16)
from Crypto.Cipher import AES
cipher=AES.new(key,AES.MODE_CBC,IV)
msg='NO, NOT SECRET!'
cip=cipher.encrypt(pad(msg))

then cip is "IS THIS SECRET??". Therefore, I don’t know if this is purely coincidental or there is some kind of algorithm that can generate the ciphertext I want by properly selecting the key and plaintext.


Solution

  • This is a bit of a puzzle, isn't it? The trick is in first decrypting the IS THIS SECRET?? string using the block cipher. Then the trickster can alter the resulting random "plaintext" by changing the IV. Look up CBC mode to see how.

    Finally, the trickster just need to add an encrypted padding block to the ciphertext. OK, since this was probably an assignment that you needed to figure out, please try and create such a weird ciphertext yourself and make it decrypt to a special message of your own.