Course contentsShow
← Security
Lesson 96 of 3,0523. Symmetric Cryptography Deep DiveFree lesson

CBC Mode: Chaining Blocks for Security

Understand Cipher Block Chaining mode, initialization vectors, and how each block depends on the previous one.

CBC Mode: Chaining Blocks for Security

What you'll learn: How Cipher Block Chaining (CBC) mode fixes ECB's critical weaknesses by linking encrypted blocks together.

The Core Problem CBC Solves

Remember ECB mode's fatal flaw? Identical plaintext blocks produce identical ciphertext blocks, creating recognizable patterns. CBC mode solves this by making each encrypted block depend on all previous blocks, breaking those patterns completely.

How CBC Works

CBC introduces two key innovations:

  1. Initialization Vector (IV): A random, unpredictable value (same size as the block) used to start the chain. Think of it as a "random seed" for your encryption.

  2. Block Chaining: Before encrypting each plaintext block, CBC XORs it with the previous ciphertext block. The first block gets XORed with the IV instead.

The Chain:

Block 1: Ciphertext₁ = Encrypt(Plaintext₁ ⊕ IV)
Block 2: Ciphertext₂ = Encrypt(Plaintext₂ ⊕ Ciphertext₁)
Block 3: Ciphertext₃ = Encrypt(Plaintext₃ ⊕ Ciphertext₂)

Why This Matters

Even if you encrypt identical plaintext blocks, they'll produce different ciphertext because each depends on everything that came before. The IV ensures that encrypting the same message twice produces completely different output.

The Analogy

Imagine a relay race where each runner receives a baton (the previous ciphertext), modifies it with their own contribution (XOR with plaintext), then passes a new baton forward. Even if two runners do identical actions, they're working with different batons, so the result differs.

Important Requirements

  • The IV must be unpredictable (typically random)
  • The IV doesn't need to be secret, just unique per encryption
  • Decryption works in reverse, using ciphertext blocks to recover plaintext

Key Takeaway: CBC mode chains blocks together using XOR and an initialization vector, ensuring identical plaintext blocks produce different ciphertext and eliminating ECB's pattern-revealing weakness.