The mathematics behind security, explained with small numbers you can check by hand, with exercises.

1 folder · 2 notes
Public Key Cryptography A four-part explainer: the mathematics behind public-key cryptography with small worked examples, then how SSH, OpenPGP, TLS, WireGuard, FIDO2 and Signal use it. 13 notes
How a TOTP Code Is Calculated The maths behind the six-digit codes of an authenticator app: HMAC, a time counter and dynamic truncation, with a Python version you can check yourself.Nov 28, 2026
Key Derivation Function Key Derivation FunctionOct 28, 2016
README.md PDF

➗ Math

The mathematics I need to understand what my security tools actually do: why an SSH key can prove who you are, how an authenticator app makes its six digits, why a password must be stretched before it becomes a key. Every page works with small numbers you can check by hand (or with pow() in Python), and most have exercises with hidden answers.

🧭 Where to start

If you want to…Read
understand what SSH, PGP, HTTPS and S/MIME keys really doPublic-key cryptography: from the mathematics to SSH, PGP and HTTPS
practise until it clicksthe ✏️ practice pages, starting with clock arithmetic
know why primes are everywhere in cryptographyPrime numbers
know why real keys have 77 to 925 digitsWhy 77 to 925 digits?
see how an authenticator app calculates its codesHow a TOTP code is calculated
know how a password becomes an encryption keyKey derivation functions

🔑 The public-key cryptography series

  1. The mathematics: clock arithmetic, RSA, Diffie–Hellman, elliptic curves, signatures
  2. How an SSH connection is built
  3. How OpenPGP (GnuPG) encrypts and signs
  4. TLS, WireGuard, FIDO2 and Signal
  5. S/MIME: email encryption with certificates

✏️ How to use the exercises

  • Work out each exercise on paper first, then click Answer.
  • Every page has a PDF button (top right): a LaTeX-style print version, with all answers shown. Handy to work through offline.
  • Check any number yourself in Python 3.8 or later:
pow(5, 13, 23)          # 5^13 mod 23 = 21        (clock arithmetic)
pow(17, -1, 2668)       # the inverse of 17 = 157  (RSA private exponent)
import math; math.gcd(2773, 2491)   # 47           (a shared prime)

🔗 Where this is used