The safe modes
The CBC mode (chaining)
ECB's flaw comes from its lack of memory: each block ignores the others. The CBC mode fixes this by chaining the blocks, so that each one depends on everything that precedes it.
The idea of chaining
CBC stands for Cipher Block Chaining. Before encrypting a plaintext block, we combine it with a XOR with the previous ciphertext block.
clair_i XOR chiffré_(i-1) --[ AES, clé K ]--> chiffré_i
Thus, the result of one block influences the next, which influences the next, and so on: a chain reaction.
The initialization vector
One problem remains: the first block has no predecessor. So we introduce an initialization vector (IV), a random block that plays the role of the "previous ciphertext" for the very first block.
IV clair_1 clair_2 clair_3
| | | |
+--> XOR +--> XOR +--> XOR ...
| ^ | ^ |
[AES K] | [AES K] | [AES K]
| | | | |
+--> chiffré_1 +--> chiffré_2 ...
|___________| |_________|
(réinjecté) (réinjecté)
Each ciphertext block is fed back into the XOR of the next block. The IV is not secret: it is transmitted in the clear with the message. But it must be random and unique for each encryption.
Why this solves the penguin problem
Thanks to chaining and the random IV, two identical plaintext blocks give different ciphertext blocks: each has been XORed with a different previous ciphertext.
Même clair, deux chiffrements avec IV différents :
chiffrement 1 : [ 2C9F... ] [ A047... ] ...
chiffrement 2 : [ E1B3... ] [ 5D8A... ] ...
-> aucune ressemblance visible
Encrypted twice, the same message gives two totally different results. The penguin, in CBC, becomes a genuine cloud of noise.
The vital importance of the IV
The IV must be unpredictable and must never repeat with the same key. Reusing an IV leaks information: if two messages start the same way, a constant IV will produce identical first ciphertext blocks — ECB's flaw comes back in through the window.
| Règle sur l'IV | Conséquence si violée |
|---|---|
| Random | predictable starting patterns |
| Unique per message | leak between messages |
| Can be public | (no problem, it is not a secret) |
In summary
- CBC chains the blocks: each plaintext is XORed with the previous ciphertext before being encrypted.
- A random initialization vector (IV) serves as the starting point for the first block.
- Result: identical plaintext blocks give different ciphertexts — ECB's flaw disappears.
- The IV must be random and unique; it can be public, but never reused with the same key.

