Level 7: AES in ECB mode

Task

The Base64-encoded content in this file has been encrypted via AES-128 in ECB mode under the key

"YELLOW SUBMARINE".

(case-sensitive, without the quotes; exactly 16 characters; I like "YELLOW SUBMARINE" because it's exactly 16 bytes long, and now you do too).

Decrypt it. You know the key, after all.

Easiest way: use OpenSSL::Cipher and give it AES-128-ECB as the cipher.

Do this with code.


Explanation

What is AES?

AES (Advanced Encryption Standard) is a symmetric cipher algorithm that operates on 16-byte blocks. It is widely used for secure data encryption. AES supports several operation modes, including ECB, CBC, and GCM, among others.

What is ECB?

ECB (Electronic Codebook) is one of the operation modes of AES-128. It determines how AES processes multiple data blocks. In ECB mode, the message is split into 16-byte blocks, and each block is encrypted or decrypted independently using the same key.

However, ECB does not use an Initialization Vector (IV), a random value that provides additional security. As a result, ECB is vulnerable to certain attacks, especially when encrypting repetitive or structured data.

In this exercise, we need to use AES-128-ECB because the cipher key is already provided.


Resolution

First, we are going to create a file named task7.py

Understanding the code

  • AES and base64 libraries are imported to handle AES decryption and Base64 decoding.

  • The script opens the 7.txt file with open() in read mode, assigning its content to the encrypted_base64 variable.

  • encrypted_base64 is then Base64 decoded and stored in the encrypted_bytes variable.

  • The key variable is initialized with the string YELLOW SUBMARINE, which is the decryption key provided in the challenge.

  • cipher is created as a new AES object, where the key and AES.MODE_ECB are passed as parameters.

  • decrypted_bytes is initialized by decrypting encrypted_bytes using the cipher.decrypt() method.

  • decrypted_text is initialized with decrypted_bytes decoded to "UTF-8", converting the bytes to a readable string.

  • Finally, decrypted_text is printed, revealing the plaintext message.


Result

The result is the same that task 6.

Last updated