ECB Shows the Pattern
In ECB mode every block is encrypted on its own, so equal plaintext blocks give equal ciphertext blocks; the repeats are visible in the ciphertext without the key.
The question
ECB, the electronic codebook mode, is the simplest way to encrypt a long message: cut it into blocks and encrypt each block with the same key. What does that leave visible in the ciphertext to someone who does not have the key?
SP 800-38A section 6.1 defines ECB encryption as C_j = CIPH_K(P_j): the cipher is applied directly and independently to each block. The lesson runs real AES-128 through OpenSSL on a message that repeats one block and looks at the blocks that come out. The key is test material and is written in the command.
Work it by hand
The demo message is 48 bytes: YELLOW SUBMARINE, YELLOW SUBMARINE, sixteen more byt. That makes three blocks. The padding of the previous lesson adds a fourth block of sixteen 10 bytes, because the message is a whole number of blocks.
Blocks 0 and 1 are the same 16 bytes. The key is the same for every block, and each block is encrypted without looking at the others. So the two ciphertext blocks must be the same too, and block 2 and the padding block must differ from them. The run below checks that prediction; nothing about the key is needed to make it.
Run it
The command encrypts the 48 bytes in the data box with AES-128 in ECB mode, under the test key written in the command, and writes 64 bytes: four blocks of 16.
The picture shows the message in three lines and the ciphertext in four lines of 16 bytes. The first two lines of the ciphertext are the same bytes, as predicted.

Public test material, generated for this lesson. Never use it for anything real.
# Encrypts in/message.bin with AES-128 in ECB mode, result in out.bin.
# The key is public test material.
openssl enc -aes-128-ecb -K 2b7e151628aed2a6abf7158809cf4f3c -nosalt \
-in in/message.bin -out out.bin
{
"answer": "3a2cd90564a2724234c4f9ec04b833d03a2cd90564a2724234c4f9ec04b833d07725293c5fbc534d681076dab8d80600a254be88e037ddd9d79fb6411c3f9df8",
"file": "out.bin",
"bytes": 64
}You can change the message to any whole number of bytes, written as hex pairs, up to 1024 bytes. Change one byte inside the first block and the first two ciphertext lines stop being equal. The empty message is accepted too.
Your turn
The program below is meant to return how many 16-byte blocks of a ciphertext are equal to an earlier block of the same ciphertext. The ciphertext was made with AES-128 in ECB mode, under the test key, from a message of whole blocks. Decide whether the program does what the question says, and find the candidates that do. Check runs each candidate on the data shown and on five others.

Public test material, generated for this lesson. Never use it for anything real.
let blocks = hex_len(cipher) / 16;
let answer = 0;
let first = hex_slice(cipher, 0, 16);
for (i in range(1, blocks)) {
let cur = hex_slice(cipher, i * 16, 16);
if (cur == first) { answer = answer + 1; }
}
{
"answer": 0
}cipher is the hex text of a ciphertext made with AES-128 in ECB mode, under one key, from a message of whole 16-byte blocks. Return how many of its 16-byte blocks are equal to an earlier block of the same ciphertext (the first block never counts). Check runs each candidate on the data shown and on five others.
Read the result carefully
The count is a comparison of ciphertext blocks. It needs no key and no AES, which is the point: anyone who holds the ciphertext can do it. It says that two plaintext blocks were equal, not what they were. This page shows a pattern in bytes; it does not show a picture, and it does not show how much a real message would give away.
The program reads whole blocks; a trailing part shorter than 16 bytes is ignored, and an empty input gives 0. The test key is public test material. ECB is shown for what it does; the later lessons show other modes, and none of them detects a change, which the last lesson of this book shows.
Recap
- ECB encrypts every block alone: C_j = CIPH_K(P_j) (SP 800-38A, section 6.1).
- Equal plaintext blocks give equal ciphertext blocks, so repeats show without the key.
- In the demo, ciphertext blocks 0 and 1 are the same 16 bytes.
- The comparison needs no key; it reveals equality of blocks, not their content.