An encryption mode where each plaintext block is XORed with the previous ciphertext block before encryption, hiding patterns but vulnerable to certain attacks.
Cipher Block Chaining (CBC) is an encryption mode where each plaintext block is XORed with the previous ciphertext block before encryption. This chains blocks together, preventing the pattern leakage found in ECB mode.
Encryption:
C[0] = IV (Initialization Vector)
C[i] = Encrypt(P[i] XOR C[i-1], Key)
Decryption:
P[i] = Decrypt(C[i], Key) XOR C[i-1]
// First block uses IV instead of previous ciphertext
P[1] P[2] P[3]
│ │ │
▼ ▼ ▼
IV ──► [XOR] ──► [Encrypt] ─┬─► [XOR] ──► [Encrypt] ─┬─► [XOR] ──► [Encrypt]
│ │
▼ ▼
C[1] C[2] C[3]