← Back

Block Cipher Modes

Comparing ECB, CBC, and CTR modes of operation

ECB (Electronic Codebook)

P1
P2
P3
E(K)
E(K)
E(K)
C1
C2
C3
Each block encrypted independently with same key. Identical plaintext blocks produce identical ciphertext blocks.
⚠️ INSECURE - Patterns preserved

CBC (Cipher Block Chaining)

IV
P1
P2
P3
E(K)
E(K)
E(K)
C1
C2
C3
Each block XORed with previous ciphertext before encryption. IV provides randomization.
✓ Secure - Patterns hidden

CTR (Counter Mode)

N|1
N|2
N|3
E(K)
E(K)
E(K)
P
C1
C2
C3
Encrypts counter values, XORs with plaintext. Parallelizable and allows random access.
✓ Secure - Stream cipher mode

ECB Penguin Demo - Why Patterns Matter

The famous "ECB Penguin" demonstrates why ECB mode is dangerous for images

Original Image
ECB Encrypted
CBC Encrypted
CTR Encrypted

Notice how ECB preserves the image patterns because identical blocks produce identical ciphertext. CBC and CTR produce random-looking output that hides all patterns. This is why ECB should never be used for encrypting data with patterns or structure.