Skip to content
Tutorials Center
My learning

Topics

Lesson 4 of 40 ยท Getting Started

Cryptanalysis and Attack Models

Learn what cryptanalysis is and the four classic attack models (ciphertext-only, known-plaintext, chosen-plaintext, chosen-ciphertext), plus brute force and dictionary attacks.

Cryptography is the craft of designing ways to protect information. Cryptanalysis is the opposite craft: studying a cipher or protocol to find weaknesses, and ideally to recover plaintext or keys without being given the key. Together they make up cryptology, the science of secret communication. Designers cannot prove their work is strong by looking at it only from their own side, so every serious design is attacked, in public, for years, by people trying to break it.

To talk about security precisely we need to say what the attacker can do. A cipher that survives an attacker who only sees ciphertext may fall to one who also knows a few plaintexts. This lesson introduces the standard attack models, then shows two of the most common practical attacks, brute force and dictionary attacks, in running code.

Terminology

  • Plaintext is the readable message, ciphertext the scrambled result, and the key is the secret parameter that controls the transformation.
  • A cryptosystem is the whole package: the algorithm, the key space and the message formats.
  • Kerckhoffs's principle says a system must stay secure even if everything about it except the key is public. Assume the attacker knows the algorithm; hiding it is not a defense.
  • An attack is any method that recovers plaintext or key faster than trying every key. Breaking a cipher in the academic sense means finding such a shortcut, even if it is still too expensive to run in practice.

The four attack models

The models are ordered by how much power they give the attacker. A cipher secure against a stronger model is also secure against the weaker ones.

Model The attacker has Typical use
Ciphertext-only (COA) Only intercepted ciphertext Eavesdropping on a radio link
Known-plaintext (KPA) Some plaintext/ciphertext pairs Messages with predictable headers, such as GET / HTTP/1.1
Chosen-plaintext (CPA) The ability to get chosen plaintexts encrypted A service that encrypts user input, a captured encryption device
Chosen-ciphertext (CCA) The ability to get chosen ciphertexts decrypted Padding-oracle attacks on servers that reveal decryption errors

A variant called adaptive chosen-plaintext (or chosen-ciphertext) attack means the attacker picks each query after seeing the answers to the previous ones. Modern definitions of security (such as IND-CCA2) assume this strongest, adaptive attacker. That is why authenticated encryption is the standard today: it makes tampered ciphertext fail before any decryption result can leak.

Two further ideas appear in the literature:

  • Differential cryptanalysis studies how a chosen difference between two plaintexts propagates to a difference between the ciphertexts. It is a chosen-plaintext technique, and block ciphers like AES are designed with it in mind.
  • Linear cryptanalysis is a known-plaintext technique that looks for linear approximations between plaintext bits, key bits and ciphertext bits.

Known plaintext in action

Known-plaintext attacks are devastating against ciphers that reuse a keystream. In the next program a "cipher" XORs the message with a repeating key. The attacker knows the message starts with Dear customer, (a very common opening). XORing that known text with the ciphertext reveals the key, and the key decrypts the rest.

Python Known-plaintext attack on a repeating-key XOR

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

This is the reason stream ciphers and the one-time pad must never reuse a keystream, and why a cipher must resist the attacker even when the plaintext is partly guessable.

Brute force

A brute-force (exhaustive key search) attack tries every key until the output looks right. It works against any cipher, so the only defense is a key space too large to search. A cipher with a k-bit key needs about 2^(k-1) trials on average. The old DES cipher (56-bit keys) was searched by dedicated hardware in a few days in 1998; 128-bit keys are far beyond any conceivable machine. See block ciphers and AES for the key-size arithmetic.

A brute-force attack needs a way to recognize success. With known plaintext, you compare. With ciphertext-only, you score candidates, for example by checking whether the result looks like English.

Dictionary attacks

People do not choose passwords uniformly at random, so an attacker does not need to try every string. A dictionary attack tries a list of likely candidates first: common words, leaked passwords and simple variations (password1, Summer2024!). It is a brute-force attack with a smart ordering, and it works offline against stolen password hashes. Tools such as John the Ripper and Hashcat apply "rules" that mutate each word.

Python A dictionary attack against unsalted hashes

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Two users fall instantly; the one with a longer, unusual password survives this wordlist. Defenses are the ones from password hashing: a per-user salt stops one table from serving all users, a slow hash such as Argon2 makes every guess expensive, and rate limiting plus multi-factor authentication limit online guessing. Relatives of the dictionary attack are the rainbow-table attack (a time-memory tradeoff that salts defeat) and credential stuffing (reusing passwords leaked elsewhere).

Why attacks on real ciphers are rare, and what they look like

Breaking AES or SHA-256 outright is not a realistic threat. Real-world failures nearly always come from something around the primitive: a reused nonce, a weak random number generator, a padding oracle, a side channel such as timing, or a human who picked a guessable password. This is the theme of common mistakes.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. In which attack model does the attacker see only intercepted ciphertext?

    Ciphertext-only is the weakest attacker: no plaintext, no encryption or decryption access.
  2. 2. A system lets an attacker submit any text and receive its encryption. Which model is this?

    The attacker chooses the plaintexts and sees the ciphertexts: a chosen-plaintext attack.
  3. 3. What does Kerckhoffs's principle say?

    A system should stay secure even when everything except the key is public.
  4. 4. Why does a per-user salt weaken dictionary attacks on stolen password hashes?

    Without a salt one precomputed table serves every user; with salts the work repeats per user.

Summary

  • Cryptanalysis studies how to break ciphers; cryptography plus cryptanalysis is cryptology.
  • Attack models, from weakest to strongest: ciphertext-only, known-plaintext, chosen-plaintext, chosen-ciphertext (often adaptive).
  • Brute force works against any cipher; only a large key space stops it.
  • Dictionary attacks exploit predictable human choices; salts, slow hashes and rate limits are the defense.
  • Most real breaks target implementations and people, not the mathematics.

Next: Modular arithmetic.