◇ OpenCyber Academy
Bachelor's · Chapter 17 · English

Chapter 17 — Cryptography concepts

Open, free learning for anyone who wants to protect people and technology. No account is required to read this text or its worked answers.

Chapter 17 — Cryptography concepts

Lesson map

Lesson 17 published. Map, example, EX049.

flowchart TD
  N0["Learning outcomes"]
  N1["17.1 Kerckhoffs's principle"]
  N2["Lab — Breaking a Caesar cipher"]
  N3["17.2 Why classical ciphers fail"]
  N4["17.3 Modern goals"]
  N5["Synthesis"]
  N0 --> N1 --> N2 --> N3 --> N4 --> N5
  N5 --> EX["Worked example"]
  EX --> Q["Exercise EX049"]

Logical drawing

flowchart LR
  N0["Learning outcomes"]
  N1["17.1 Kerckhoffs's principle"]
  N2["Lab — Breaking a Caesar cipher"]
  N3["17.2 Why classical ciphers fail"]
  N4["17.3 Modern goals"]
  N5["Synthesis"]
  N0 --> N1 --> N2 --> N3 --> N4 --> N5 --> Q["EX049"]
[Learning outcomes]
    |
    v
[17.1 Kerckhoffs's principle]
    |
    v
[Lab — Breaking a Caesar cipher]
    |
    v
[17.2 Why classical ciphers fail]
    |
    v
[17.3 Modern goals]
    |
    v
[Synthesis]
    |
    v
[Worked example] --> [Exercise EX049]

Learning outcomes

You will (1) explain Kerckhoffs's principle; (2) show why classical ciphers fail; (3) define modern security goals such as indistinguishability.

17.1 Kerckhoffs's principle

A cipher should remain secure even if everything about it except the key is public. This principle, stated by Auguste Kerckhoffs in the nineteenth century, guides modern cryptography: AES is fully published in FIPS 197, and its security rests on the secrecy of keys. Priya learns why secret algorithms are a poor bet: they get reverse-engineered, they receive little public scrutiny and changing them is expensive. Public, well-analysed standards concentrate expert attention where weaknesses can be found and fixed early. Tidewell's suppliers are asked to confirm they use published algorithms.

Lab — Breaking a Caesar cipher

"""Break a toy Caesar cipher by frequency analysis to show why classical ciphers fail."""
from collections import Counter
TEXT = "THE LIBRARY OPENS AT NINE AND THE READING ROOM CLOSES AT EIGHT EVERY EVENING"

def shift(s, k):
    return "".join(chr((ord(c) - 65 + k) % 26 + 65) if c.isalpha() else c for c in s)

def main():
    ct = shift(TEXT, 11)
    top = Counter(c for c in ct if c.isalpha()).most_common(1)[0][0]
    k = (ord(top) - ord("E")) % 26
    print("ciphertext:", ct[:30], "...")
    print("most common letter:", top, "-> guessed shift", k)
    print("recovered:", shift(ct, -k)[:30], "...")
    print("keys to try by brute force:", 25)

if __name__ == "__main__":
    main()

Run with python3 lab_caesar.py. Verified output:

ciphertext: ESP WTMCLCJ ZAPYD LE YTYP LYO  ...
most common letter: P -> guessed shift 11
recovered: THE LIBRARY OPENS AT NINE AND  ...
keys to try by brute force: 25

17.2 Why classical ciphers fail

The lab encrypts a sentence about library hours with a Caesar shift of 11. The most common ciphertext letter is P, and assuming it stands for E, the most common English letter, gives the shift 11 and recovers the text. Even without frequency analysis, only 25 shifts exist, so brute force is instant. Priya extends the lesson: substitution ciphers preserve letter patterns, and any cipher that leaks structure about the plaintext can be attacked statistically. The Handbook of Applied Cryptography, chapter 7, surveys such classical systems and why they were abandoned.

17.3 Modern goals

Modern cryptography defines security precisely. Katz and Lindell describe indistinguishability: an attacker who chooses two messages and sees the encryption of one should not be able to tell which, with probability meaningfully better than a coin toss. This rules out leaking patterns, lengths aside. A deterministic scheme, where the same message always encrypts the same way, fails this definition because repeated messages are visible. That is why modern encryption uses random or unique nonces and why authenticated encryption also guarantees integrity.

Worked example

Priya breaks a shift-11 Caesar cipher by frequency analysis, explains Kerckhoffs's principle using FIPS 197, and shows why deterministic encryption fails indistinguishability.

Synthetic case. The message is invented; FIPS 197 and the Handbook are real.

Errors and limits

Indistinguishability does not hide message length. Classical ciphers are for history and teaching, never protection.

Exercises

Synthesis

Public algorithms, precise definitions and randomised encryption replaced classical ciphers whose patterns gave them away.

Continue studying — chapter 17 of 40

← Chapter 16 (draft) · Course chapter index · Chapter 18 (draft) →