Skip to content
BoKSA

B8. Cryptography

B8. Cryptography

Level Foundation and Intermediate (with a step towards Advanced: hashing and password storage)
Prerequisites B1, B2, B3, B5, B6, and for Intermediate B4
Study time About 12 hours (5 h reading and video, 7 h hands-on)
Source Teach-the-Teachers fiche B8
Next topics B9 Incident response · B11 Penetration testing

Why this matters

Cryptography is everywhere, mostly invisibly. It is in the padlock in your browser (TLS), your WhatsApp or Signal messages (end-to-end encryption), your bank card chip, your laptop's disk encryption, software updates (digital signatures), the way your password is stored (hashing) and passkeys. It is the main technical tool for confidentiality and integrity (see B5).

You won't design new algorithms. You will constantly have to:

  • choose the right building block (encrypt, hash or sign?),
  • configure it correctly (TLS versions, key lengths, certificates),
  • manage keys,
  • recognise when cryptography is used wrongly.

Wrong use is very common. OWASP's Cryptographic Failures (A04:2025) covers exactly that: plain-text passwords, outdated algorithms, hard-coded keys. And new developments, such as post-quantum cryptography, are changing the field right now.

Learning objectives

Foundation. After this topic you can:

  1. Tell the story of cryptography in a few key steps and explain why it matters.
  2. Explain and use simple ciphers (Caesar/ROT13).
  3. Identify the elements needed to encrypt and decrypt (plaintext, ciphertext, algorithm, key).

Intermediate. In addition you can:

  1. Relate cryptographic building blocks to the CIA triad.
  2. Explain the difference between symmetric and asymmetric cryptography, and why we combine them.
  3. Explain the basics of key management, including certificates.

Towards Advanced. You can also explain what a hash function is, how passwords should be stored, and name some attacks on ciphers.

Foundation: the story and the basics

A short history

When What
~500 BC The Spartan scytale: a strip wrapped around a rod (transposition)
~50 BC The Caesar cipher: shift every letter by a fixed number (substitution)
9th century Al-Kindi describes frequency analysis, which breaks simple substitution
1553–1586 The Vigenère cipher uses a keyword for multiple shifts; long thought "unbreakable"
1883 Kerckhoffs's principle: a system must be secure even if everything except the key is public
1930s–1945 The German Enigma machine. Polish mathematicians, and then Alan Turing and colleagues at Bletchley Park, break it
1976–1977 Diffie–Hellman key exchange and RSA: public-key cryptography is born. DES becomes the US standard
2001 AES replaces DES; it is still the standard for symmetric encryption
1990s–today TLS secures the web; end-to-end encrypted messaging (Signal protocol, 2013–)
2024 NIST publishes the first post-quantum standards (FIPS 203, 204, 205)

The elements of encryption

  • Plaintext: the readable message.
  • Ciphertext: the encrypted, unreadable result.
  • Algorithm (cipher): the method, such as Caesar or AES.
  • Key: the secret parameter, such as "shift by 3" or a 256-bit AES key.
  • Encryption turns plaintext into ciphertext with the key; decryption reverses it.

Following Kerckhoffs's principle, the algorithm is public and only the key is secret. AES is published and studied worldwide; that is exactly why we trust it. Security that depends on keeping the method secret (security through obscurity) breaks as soon as the method leaks.

The Caesar cipher and ROT13

Shift every letter by k positions. With k = 3: A→D, B→E, … Z→C. ROT13 is the special case k = 13: applying it twice gives the original text.

Try the fiche's classroom puzzle: serr cvmmn va gur pnsrgrevn. (The answer is in Check yourself below.)

A Caesar cipher has only 25 possible keys, so you can try them all in seconds (brute force). Even with a random substitution of the alphabet (26! ≈ 4 × 10²⁶ keys), frequency analysis breaks it: in English, E, T and A are the most common letters, and the pattern survives encryption. Modern ciphers are designed so that the ciphertext shows no patterns and the number of keys is astronomically large (2¹²⁸ or 2²⁵⁶).

Encoding, encryption and hashing are different

Purpose Reversible? Needs a key? Example
Encoding Represent data in another format Yes, by anyone No Base64, hex, URL encoding
Encryption Keep data secret Yes, with the key Yes AES, RSA
Hashing Fingerprint of data; check integrity No (one-way) No SHA-256

Base64 is not encryption. If you find a "secret" in Base64 in a config file or a CTF, it is simply readable.

Intermediate: modern cryptography

Cryptography and the CIA triad

Building block Protects Example
Symmetric / asymmetric encryption Confidentiality Disk encryption, HTTPS, messaging
Hash function Integrity (detects change) Checksums of downloads
MAC / HMAC (hash with a secret key) Integrity + authenticity between parties who share a key API request signing, TLS records
Digital signature Integrity + authenticity + non-repudiation Software updates, Secure Boot, e-mail signing, certificates

Symmetric cryptography: one shared key

The same key encrypts and decrypts. Modern standards are AES (128 or 256-bit keys) and ChaCha20. They are very fast, so they are used for all bulk data: your disk, your Wi-Fi, the content of an HTTPS session.

The problem: key distribution. How do two people who have never met agree on a secret key, if the only channel they have is the Internet, where anyone can listen? (This is the fiche's discussion question P1.) With n people who all want to talk privately, you also need n(n−1)/2 keys: 4,950 keys for 100 people.

Asymmetric (public-key) cryptography: a key pair

Each person has a key pair:

  • a public key, which you can give to everyone, and
  • a private key, which never leaves you.

What one key does, only the other can undo:

  • Encryption: anyone encrypts with your public key; only your private key decrypts. Think of a padlock that anyone can close but only you can open.
  • Signing: you sign with your private key; anyone can verify with your public key. This proves the message came from you and was not changed.

Algorithms are RSA (2048 bits or more) and elliptic-curve cryptography (ECC, such as X25519 and Ed25519, with much shorter keys for the same strength). Asymmetric operations are slow, so they are only used for small things: exchanging a key or signing a hash.

Diffie–Hellman key exchange solves the key distribution problem: two parties each combine their own secret with public values and end up with the same shared secret, while an eavesdropper who sees all public values cannot compute it. The usual "mixing paint colours" analogy explains it well (see the videos below).

Hybrid encryption: how HTTPS really works

TLS (the S in HTTPS) combines both:

  1. Your browser and the server do a key exchange (Elliptic-curve Diffie–Hellman) to agree a fresh symmetric session key.
  2. The server proves its identity with a certificate and a signature (asymmetric).
  3. All data is then encrypted with the fast symmetric session key (AES-GCM or ChaCha20-Poly1305).

Key management and certificates

Cryptography is only as strong as the protection of its keys. Key management covers the whole life of a key:

Generate (with a good random source) → distribute → store (protected: TPM, smartcard, hardware security module, key vault) → use → rotate (replace regularly) → revoke (if compromised) → destroy.

How do you know a public key really belongs to hva.nl and not to an attacker? A certificate is a public key plus an identity, digitally signed by a trusted Certificate Authority (CA). Your browser and OS ship with a list of trusted root CAs. This system is called PKI (Public Key Infrastructure). Free, automated certificates from Let's Encrypt have made HTTPS the default on the web.

Typical key management failures: private keys in source code or on GitHub, keys that are never rotated, a single person who knows the backup key, and certificates that expire unnoticed (an availability incident).

Towards Advanced: hashes, passwords and attacks

Hash functions

A cryptographic hash function turns input of any size into a short, fixed-length digest (hash). SHA-256 gives 256 bits, shown as 64 hex characters. Required properties:

  • One-way: from the hash you can't compute the input.
  • Collision resistant: it is infeasible to find two inputs with the same hash.
  • Avalanche effect: changing one bit of input changes about half the output bits.

Use SHA-256 or SHA-3. MD5 and SHA-1 are broken for collision resistance and must not be used for security.

How passwords should be stored

A system should never store your password, not even encrypted. It stores a salted, slow hash:

  1. When you register, the system generates a random salt (unique per user), computes hash(salt + password) with a deliberately slow password-hashing function, and stores the salt and the hash.
  2. When you log in, it computes the same with what you typed and compares.

Hashing is one-way: it is not encryption, and there is no key to steal. If the database is stolen, attackers must guess: they hash candidate passwords and compare. The salt stops precomputed tables (rainbow tables) and identical passwords giving identical hashes. The slowness (Argon2id, scrypt, bcrypt or PBKDF2) makes each guess expensive, which stops a GPU from testing billions per second. Long, unique passwords then make guessing hopeless. That is why password length matters (B7).

A pepper is an extra secret added to all passwords and stored outside the database (for example in a key vault), so a stolen database alone is not enough.

Attacks on ciphers

Attack Idea Example
Brute force Try every key Trivial for Caesar; infeasible for AES-128 (2¹²⁸ keys)
Frequency analysis Statistical patterns in the ciphertext Breaks substitution ciphers
Known-plaintext Use pieces of plaintext you know or can guess, together with their ciphertext How Enigma was broken: Bletchley Park guessed likely words ("cribs", such as Wetterbericht, weather report) and used the Bombe machines to find the day's settings
Chosen-plaintext Get the system to encrypt texts of your choice Relevant for modern protocol analysis
Side channel Measure time, power use or radiation instead of attacking the maths Timing attacks; Spectre (B2)
Implementation / usage errors Weak random numbers, reused keys or nonces, home-made crypto The most common real-world failure

Post-quantum cryptography

A large enough quantum computer could break RSA and elliptic-curve cryptography (with Shor's algorithm). Symmetric ciphers and hashes are much less affected; longer keys are enough. In 2024 NIST published the first post-quantum standards:

  • FIPS 203 ML-KEM for key exchange,
  • FIPS 204 ML-DSA and FIPS 205 SLH-DSA for signatures.

Browsers and messaging apps already use hybrid post-quantum key exchange. Why start now? "Harvest now, decrypt later": an adversary can record encrypted traffic today and decrypt it once a quantum computer exists. Data that must stay secret for 20 years must therefore be protected now.

In practice

Exercise 1: break classical ciphers (Foundation, 45 min)

  1. Decrypt serr cvmmn va gur pnsrgrevn by hand, then check with ROT13 in CyberChef.
  2. Encrypt a sentence for a classmate with a Caesar shift of your choice. Let them break it with brute force (CyberChef: "ROT13" with different amounts).
  3. Do the Caesar cipher activities on Interactivate, or build a paper Enigma machine (PDF).

Exercise 2: hashing (Intermediate, 20 min)

In PowerShell:

1
2
3
$t = "free pizza in the cafeteria"
$b = [Text.Encoding]::UTF8.GetBytes($t)
[BitConverter]::ToString([Security.Cryptography.SHA256]::Create().ComputeHash($b))

Or in Linux: echo -n "free pizza in the cafeteria" | sha256sum. Change one letter and compare the hashes (avalanche effect). Also try CyberChef's "SHA2" and "MD5" operations.

Exercise 3: encrypt and sign with GnuPG (Intermediate, 1 h, in pairs)

Install GnuPG (Windows: Gpg4win with Kleopatra).

1
2
3
4
5
6
7
gpg --full-generate-key                        # create your key pair
gpg --armor --export you@example.com > me.asc  # share your PUBLIC key
gpg --import partner.asc                       # import your partner's public key
gpg --encrypt --armor -r partner@example.com secret.txt
gpg --clearsign message.txt                    # sign
gpg --verify message.txt.asc                   # partner verifies
gpg --decrypt secret.txt.asc                   # partner decrypts

Explain for each step which key (whose public or private key) was used and why.

Exercise 4: inspect a real certificate (Intermediate, 20 min)

Click the padlock in your browser on https://www.hva.nl and view the certificate: who issued it, what is the validity period, which key algorithm is used? Then run the site through SSL Labs Server Test and explain the grade.

Exercise 5: learn by solving (Intermediate → Advanced)

Make an account on CryptoHack and solve the Introduction and General courses (encoding, XOR, modular arithmetic). This is excellent preparation for crypto challenges in Capture the Flag competitions.

Tools

Tool What you use it for Cost
CyberChef Encode, decode, encrypt and hash in the browser ("the cyber Swiss army knife") Free
dCode Identify and break classical ciphers Free
GnuPG / Gpg4win Encrypt and sign files and e-mail Free
VeraCrypt Encrypted containers and disks Free
SSL Labs Server Test Analyse a website's TLS configuration Free
CryptoHack Learn cryptography through challenges Free

Videos

Handouts and reading

Literature and courses

  • Singh, S. The Code Book (1999). The history of cryptography, from Caesar to RSA, told as a page-turner (Foundation).
  • Paar, C., Pelzl, J. & Güneysu, T. Understanding Cryptography (2nd ed., Springer, 2024). The standard student textbook; see the book's website for slides and links to the authors' video lectures (Intermediate).
  • Aumasson, J.-P. Serious Cryptography (2nd ed., No Starch Press, 2024). Practical modern cryptography (Intermediate → Advanced).
  • Crypto 101, a free introductory book.
  • 🎓 Cryptography I – Dan Boneh, Stanford (Coursera) (Advanced).
  • CyBOK Cryptography KA and our summary CyBOK 18.1-2 Crypto schemes and protocols.

Common mistakes

  • "Encrypted hash." A hash is not encryption, and passwords are not stored "encrypted". They are stored as salted, slow hashes.
  • Base64 = encryption. Base64 is encoding; anyone can reverse it.
  • Rolling your own crypto. Use well-known libraries and standard algorithms. Home-made schemes almost always fail.
  • Using MD5 or SHA-1, or a fast hash such as plain SHA-256 for passwords. Use Argon2id, scrypt, bcrypt or PBKDF2 for passwords.
  • Putting private keys in code. Secrets belong in a key vault or secret manager, never in a repository.
  • Ignoring certificate warnings. They are exactly the alarm that detects a man-in-the-middle.

Check yourself

  1. What is the aim of encryption, and why do we need a key?
  2. Decrypt serr cvmmn va gur pnsrgrevn. Which shift was used?
  3. What is the difference between symmetric and asymmetric cryptography? Why does HTTPS use both?
  4. To send Alice a secret message, which key do you use? And to prove a message came from you?
  5. Why is key management needed, and name three steps in the life of a key.
  6. How should a website store your password, and what is the purpose of the salt?
  7. What kind of attack broke Enigma?
Answers

1. To keep information confidential. The algorithm is public (Kerckhoffs), so the secret key is what stops others from decrypting.
2. "free pizza in the cafeteria", with a shift of 13 (ROT13).
3. Symmetric uses one shared key and is fast; asymmetric uses a public/private key pair and solves key distribution and signing, but is slow. HTTPS uses asymmetric cryptography to authenticate and agree a key, and symmetric cryptography for the bulk data.
4. Alice's public key for the secret message; your own private key to sign.
5. Because cryptography is only as strong as the secrecy and correct handling of keys. Generate, distribute, store, rotate, revoke, destroy.
6. As a salted hash computed with a slow password-hashing function (for example Argon2id). The salt makes every user's hash unique and defeats precomputed tables.
7. Mainly a known-plaintext attack: guessed words ("cribs") combined with the Bombe machines.