Cyber Trainer Crypto Primer
Crypto Primer · Chapter 05

Modern cryptosystems

Computers changed everything. Ciphers now work on bits rather than letters, keys are hundreds of bits long, and in 1976 a new idea solved the problem that had dogged cryptography for 3,000 years: how to agree a secret with someone you've never met.

Milestones

Symmetric ciphers

AlgorithmTypeKeyStatus
DES64-bit block, Feistel network, 16 rounds56-bitbroken Brute-forceable.
3DESDES three times (encrypt-decrypt-encrypt)112/168-bitretired NIST disallowed it for encryption after 2023. Its 64-bit block is open to Sweet32.
RC4Stream cipher40–2048-bitbroken Biased keystream. Used in WEP, WPA-TKIP and old TLS.
AES128-bit block, substitution-permutation network128/192/256-bitstandard Hardware-accelerated (AES-NI) on almost every CPU.
ChaCha20Stream cipher (add-rotate-XOR)256-bitstandard Fast in software on phones without AES hardware.
What happens inside an AES round?

AES arranges each 16-byte block as a 4×4 grid and repeats four steps 10, 12 or 14 times:

  1. SubBytes: every byte goes through a fixed substitution table, the S-box (confusion).
  2. ShiftRows: each row is rotated by a different amount (diffusion across columns).
  3. MixColumns: each column is mixed so every output byte depends on all four input bytes (diffusion).
  4. AddRoundKey: the block is XORed with a round key derived from the main key.

After two rounds every output bit depends on every input bit. That's the avalanche effect from Chapter 02.

Real AES-256-GCM in your browser

Salt · IV (nonce) · ciphertext + 128-bit authentication tag

Encrypt the same text twice and you get different ciphertext, thanks to the random salt and IV. Tamper with it and GCM's tag check rejects the whole message. That's authenticated encryption at work.

Public-key (asymmetric) cryptography

Think of a padlock you can hand out freely. Anyone can snap it shut (encrypt with your public key), but only you have the key that opens it (decrypt with your private key). Run it the other way round and you get signatures: only you can make a mark with your private key, and anyone can check it with your public key.

This works because of trapdoor functions: maths that's easy one way and practically impossible to reverse without a secret.

  • RSA: multiplying two large primes is easy, but factoring the product back into those primes is very hard.
  • Diffie-Hellman: raising a number to a power modulo a prime is easy, but recovering the exponent (the discrete logarithm) is very hard.
  • Elliptic curves: the same idea on the points of a curve, which gives much smaller keys for the same strength.

Diffie-Hellman key exchange

DH lets two people agree a shared secret over a channel an eavesdropper can watch. It's often explained with paint. Mixing colours is easy, but un-mixing them is practically impossible.

Mix a shared secret

👩 Alice

Public colour + secret =
Bob's mix + her secret =

👨 Bob

Public colour + secret =
Alice's mix + his secret =

👁 Eve sees the public colour and both mixes, but she can't separate the secret colours out of them. Alice and Bob end up with the same final colour.

Now with real (tiny) numbers

Real DH uses 2048-bit or larger primes, or elliptic curves like X25519. At that size, working back from A to a is far beyond any computer.

DH alone doesn't prove who you're talking toA man-in-the-middle can run one exchange with Alice and another with Bob. That's why TLS signs the exchange with the server's certificate (Chapter 06), and why WPA3 ties the exchange to the Wi-Fi password.

RSA

Toy RSA

Real RSA uses primes over 1,000 bits each, and always pads messages (OAEP for encryption, PSS for signatures). Without padding it's insecure.

Elliptic-curve cryptography (ECC)

ECC gives the same security as RSA with far smaller keys. That means faster handshakes, less bandwidth and less battery drain, which is why modern TLS, SSH, Signal and WPA3 prefer it. Common curves include X25519/Ed25519 (Curve25519) and NIST P-256/P-384.

Security levelSymmetricRSA / DHECC
112-bit3DES2048-bit224-bit
128-bitAES-1283072-bit256-bit
192-bitAES-1927680-bit384-bit
256-bitAES-25615360-bit512-bit

Comparable strengths from NIST SP 800-57 Part 1.

Hashing, MACs and AEAD

A cryptographic hash turns any input into a fixed-length digest. A good hash is:

  • Pre-image resistant: you can't find an input from its hash (one-way).
  • Second pre-image resistant: you can't find a different input with the same hash as a given one.
  • Collision resistant: you can't find any two inputs with the same hash. Thanks to the birthday paradox, an n-bit hash gives only about n/2 bits of collision resistance, so SHA-256 gives about 128.
Hash playground

Change one character and every digest changes completely. MD5 (128-bit) and SHA-1 (160-bit) are broken for collisions and aren't available in the browser's Web Crypto API. Use the SHA-2 or SHA-3 families.

MAC / HMAC

A hash mixed with a secret key. It proves integrity and that the sender knows the key. HMAC-SHA256 is everywhere, from API signatures to TLS 1.2 record protection.

AEAD

Authenticated Encryption with Associated Data, such as AES-GCM or ChaCha20-Poly1305, encrypts and authenticates in one step. TLS 1.3 allows only AEAD ciphers.

Password hashing

Plain SHA-256 is far too fast for passwords. Use Argon2id, scrypt, bcrypt or PBKDF2 with a unique salt for each user.

Post-quantum cryptography

A large enough quantum computer running Shor's algorithm could solve factoring and discrete logarithms efficiently, which would break RSA, DH and ECC. Symmetric crypto and hashes are much less exposed: Grover's algorithm roughly halves their effective strength, which AES-256 easily absorbs.

No such quantum computer exists yet, but there's a "harvest now, decrypt later" threat. An adversary can record encrypted traffic today and decrypt it years from now. So migration has already started:

  • ML-KEM (FIPS 203, formerly Kyber), a lattice-based key encapsulation mechanism that replaces DH/ECDH for key exchange.
  • ML-DSA (FIPS 204, formerly Dilithium) and SLH-DSA (FIPS 205, formerly SPHINCS+) for signatures.
  • Hybrid key exchange (for example X25519MLKEM768) combines classical and post-quantum algorithms, so the connection stays safe if either one holds. Major browsers and CDNs, including Cloudflare, already use it by default for a large share of TLS traffic.
UK guidanceThe NCSC has set out a migration timeline for organisations: identify where cryptography is used and plan by 2028, migrate the highest-priority systems by 2031, and complete migration by 2035.

Knowledge check