Learn the Math

Deep dive into the core ideas that power modern cryptography — from the number theory behind RSA and elliptic curves to symmetric ciphers, protocols, security definitions and cryptanalysis.

🧭

Learn by doing 🚀

Each topic below comes with a clear explanation, a hands-on calculator, a short video to go deeper, and a quiz that gets trickier as you go. Take your time, experiment, and don’t worry about mistakes — that’s how you learn!

🧮 Scientific Calculator

Crunch the numbers as you learn — supports sin, cos, tan, log, ln, √, powers, π, factorials, % and more. Tip: click the screen to use your keyboard too.

0
01

Modular Arithmetic

The foundation of modern cryptography

? What is Modular Arithmetic?

Modular arithmetic is like clock math. When the hour hand goes past 12, it wraps back to 1. In math terms, we're working with remainders after division. This simple concept is the foundation of nearly all modern encryption.

a mod n = remainder when a is divided by n

For example: 17 mod 5 = 2 (because 17 ÷ 5 = 3 remainder 2)

Key Properties

  • Addition: (a + b) mod n = ((a mod n) + (b mod n)) mod n
  • Multiplication: (a × b) mod n = ((a mod n) × (b mod n)) mod n
  • Exponentiation: Used in RSA encryption for secure key generation
  • One-way function: Easy to compute forward, nearly impossible to reverse

Try It Yourself

Modular Arithmetic Calculator

17 mod 5 = 2

Blockchain Application

In Bitcoin, modular arithmetic is used in ECDSA (Elliptic Curve Digital Signature Algorithm) to create and verify digital signatures. Every transaction you make is secured by these calculations.

💡 Did you know? Every time you send a text or open a website, modular arithmetic scrambles your data behind the scenes — billions of times a day.

🎬 Watch & Learn

Tom Rocks Maths · How does Modular Arithmetic work?

🧠 Test Yourself
02

Prime Numbers

The atoms of mathematics

? What are Prime Numbers?

A prime number is a natural number greater than 1 that can only be divided evenly by 1 and itself. These seemingly simple numbers are the building blocks of all integers and form the foundation of cryptographic security.

2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31...

The beauty of primes: every integer greater than 1 can be uniquely expressed as a product of prime numbers (Fundamental Theorem of Arithmetic).

Why Primes Matter in Cryptography

  • RSA Encryption: Uses the product of two large primes (1024+ bits each)
  • One-way trap: Multiplying primes is easy; factoring their product is extremely hard
  • Key generation: Your private keys depend on prime number properties
  • Security guarantee: No known efficient algorithm can factor large semiprimes

Try It Yourself

Prime Number Checker

97 is PRIME

Blockchain Application

While Bitcoin uses elliptic curves (not RSA), prime numbers are still crucial. The secp256k1 curve used by Bitcoin is defined over a prime field with a 256-bit prime number.

💡 Did you know? There are infinitely many primes — Euclid proved it over 2,000 years ago, and we still rely on that fact to keep secrets today.

🎬 Watch & Learn

TED-Ed · How Prime Numbers Keep the Internet Secure

🧠 Test Yourself
03

Discrete Logarithms

The one-way function

? What are Discrete Logarithms?

A discrete logarithm is the inverse of modular exponentiation. If g^x mod p = h, then x is the discrete logarithm of h to the base g, modulo p. The magic: computing g^x mod p is easy, but finding x from the result is incredibly hard.

Given g, p, and h: find x where g^x mod p = h

This asymmetry (easy one way, hard the other) is what makes public-key cryptography possible.

The Diffie-Hellman Key Exchange

  • Step 1: Alice and Bob agree on public values g and p
  • Step 2: Alice picks secret a, sends g^a mod p to Bob
  • Step 3: Bob picks secret b, sends g^b mod p to Alice
  • Step 4: Both compute (g^ab mod p) - the shared secret!

Even if an attacker sees all public communication, they cannot compute the shared secret without solving the discrete log problem.

Try It Yourself

Modular Exponentiation Calculator

5^3 mod 23 = 10

Blockchain Application

The discrete log problem on elliptic curves (ECDLP) is what secures your Bitcoin wallet. Your private key is essentially a secret exponent, and your public key is the result of elliptic curve multiplication - easy to compute, impossible to reverse.

💡 Did you know? Two strangers can agree on a secret key out in the open, while everyone watching still can’t figure it out. That’s the magic of discrete logarithms!

🎬 Watch & Learn

Khan Academy · The Discrete Logarithm Problem

🧠 Test Yourself
04

Elliptic Curves

The modern standard

? What are Elliptic Curves?

An elliptic curve is a special type of curve defined by the equation y² = x³ + ax + b. When we combine this with modular arithmetic over a prime field, we get Elliptic Curve Cryptography (ECC) - the backbone of Bitcoin and Ethereum.

y² = x³ + ax + b (mod p)

ECC provides the same security as RSA with much smaller key sizes: a 256-bit ECC key ≈ 3072-bit RSA key.

Point Operations on Curves

  • Point Addition: Given two points P and Q, we can compute P + Q geometrically
  • Point Doubling: Computing P + P = 2P using the tangent line
  • Scalar Multiplication: Computing kP by repeated doubling and adding
  • ECDLP: Given P and Q = kP, finding k is computationally infeasible

secp256k1: Bitcoin's Curve

Bitcoin uses a specific elliptic curve called secp256k1, defined by:

y² = x³ + 7 (mod p)

Where p is a massive 256-bit prime. Your Bitcoin private key is a random 256-bit number k, and your public key is the point K = k × G, where G is the generator point.

Blockchain Application

Every Bitcoin address is derived from an elliptic curve public key. When you sign a transaction, you prove ownership of the private key without revealing it - this is the magic of ECDSA (Elliptic Curve Digital Signature Algorithm).

💡 Did you know? The same elliptic-curve math that protects Bitcoin also secures the little padlock 🔒 in your browser’s address bar.

🎬 Watch & Learn

Computerphile · Elliptic Curves (Dr Mike Pound)

🧠 Test Yourself
05

Post-Quantum Cryptographic Math

The math built to survive quantum computers

Why today’s encryption is in danger

RSA and elliptic curves are safe today because reversing them (factoring huge numbers or solving discrete logs) would take normal computers billions of years. But a large quantum computer running Shor’s algorithm could do it in hours. That is the whole reason post-quantum cryptography exists.

RSA & ECC  ⟶  broken by Shor’s algorithm on a quantum computer

Lattices: hard problems in a grid of dots

Most post-quantum schemes are built on lattices — endless grids of points made by adding and subtracting a few vectors. The security comes from problems that are easy to state but brutally hard to solve, even for quantum computers.

  • Shortest Vector Problem (SVP): in a huge grid of points, find the point closest to the origin. Easy to picture, incredibly hard to compute.
  • Learning With Errors (LWE): hide a secret inside many equations, then sprinkle in tiny random noise so the equations can’t be solved.
b = A·s + e (mod q)  —  find secret s, hidden by tiny error e

🛡 The new standards

In 2024, the US standards body NIST published the first official post-quantum algorithms. These are already rolling out in browsers and messaging apps right now.

  • Kyber (ML-KEM): a lattice-based key exchange — how two devices agree on a secret quantum-safely.
  • Dilithium (ML-DSA): lattice-based digital signatures that prove who sent a message.
  • SPHINCS+ (SLH-DSA): signatures built only from hash functions — a totally different backup approach.
💡 Did you know? Hackers are already storing today’s encrypted data, hoping to crack it with future quantum computers — a strategy called “harvest now, decrypt later.”

🎬 Watch & Learn

Chalk Talk · Lattice-Based Cryptography: The Tricky Math of Dots

🧠 Test Yourself
06

Symmetric Cryptography

One shared key — the fast workhorse of encryption

? What is symmetric encryption?

In symmetric cryptography a single secret key is used to both lock (encrypt) and unlock (decrypt) a message. It is far faster than public-key math, so almost all real data — your Wi-Fi, disk encryption, and the actual content of an HTTPS page — is protected with it. Public-key crypto is mostly used just to agree on the symmetric key.

C = Ek(P)    and    P = Dk(C)

The same key k appears on both sides, so it must be shared secretly beforehand — the classic "key distribution" problem that Diffie–Hellman later solved.

The building blocks

  • Block ciphers: encrypt fixed-size chunks — AES (the worldwide standard) works on 128-bit blocks with 128- or 256-bit keys.
  • Stream ciphers: generate a keystream and XOR it with the data, bit by bit.
  • Modes of operation: CBC, CTR and GCM turn a block cipher into something safe for long messages — GCM even detects tampering.
  • Confusion & diffusion: Shannon's two design goals — hide the link between key and ciphertext, and spread each input bit across the whole output.
AES-256  ⟶  ~128-bit security even against a quantum attacker (Grover)

🔒 The one-time pad: perfect but impractical

XOR your message with a truly random key that is as long as the message and never reused, and the result is provably unbreakable — Shannon's "perfect secrecy." The catch is exactly that key: distributing one-time pads as long as all your data is why we use AES instead.

💡 Did you know? AES is so fast because modern processors run it in hardware — a dedicated AES-NI instruction encrypts billions of bytes per second, which is why full-disk encryption barely slows your laptop.

🎬 Watch & Learn

Computerphile · AES Explained (Advanced Encryption Standard)

🧠 Test Yourself
07

Cryptographic Protocols

How the pieces work together over an untrusted network

? What is a protocol?

A single cipher only scrambles data. A protocol is the choreography that combines several tools — key exchange, authentication and encryption — into a conversation that is safe even when strangers are listening. Every HTTPS padlock is one protocol, TLS, running in the background.

A typical secure session does three things: agree on a shared key (key exchange), prove who you're talking to (authentication), then encrypt the data (symmetric crypto).

🤝 The core moves

  • Key exchange: Diffie–Hellman / ECDHE let two parties agree a secret over a public wire.
  • Message authentication (MAC / HMAC): a keyed tag that proves a message wasn't altered and came from someone who holds the key.
  • Digital signatures & certificates: prove identity; a Certificate Authority signs a public key, forming the PKI that browsers trust.
  • Forward secrecy: using fresh, throwaway keys each session so a future key leak can't unlock past traffic.
HMAC(k, m) = H( (k ⊕ opad) ∥ H( (k ⊕ ipad) ∥ m ) )

🕵 Proving without revealing

Advanced protocols do surprising things. A zero-knowledge proof convinces someone a statement is true while revealing nothing else — not even the secret behind it. A commitment scheme lets you lock in a value now and reveal it later without being able to change it (it is both binding and hiding), the digital version of a sealed envelope.

💡 Did you know? Zero-knowledge proofs power modern privacy coins and "zk-rollups" that let a blockchain verify thousands of transactions while keeping their details hidden.

🎬 Watch & Learn

Computerphile · Transport Layer Security (TLS)

🧠 Test Yourself
08

Security Definitions

What it actually means for a cipher to be "secure"

? "Looks scrambled" is not enough

Real cryptography never says "it looks random, so it's safe." Instead we define a precise attacker and a precise goal, then prove the attacker can't win. This is what separates modern cryptography from historical code-making.

Advantage = | Pr[attacker wins] − ½ |  must be  negligible

A scheme is "broken" the moment an attacker does noticeably better than a coin flip — even slightly.

The vocabulary of security

  • Kerckhoffs's principle: security must rest on the secret key alone — assume the enemy already knows your algorithm.
  • Threat models: ciphertext-only → known-plaintext → chosen-plaintext (CPA)chosen-ciphertext (CCA), each giving the attacker more power.
  • Semantic security / IND-CPA: the ciphertext leaks essentially nothing about the plaintext.
  • Perfect secrecy: Shannon's gold standard, achieved only by the one-time pad.

🛡 Provable security

The strongest guarantee is a reduction: a proof that if someone could break the scheme, they could also solve a problem everyone believes is hard — like factoring huge numbers. So breaking the cipher is at least as hard as that famous open problem. Security stops being a hope and becomes a theorem.

💡 Did you know? The word "negligible" has a formal meaning here: a success chance that shrinks faster than 1 / (any polynomial) as the key grows — so big keys make a winning attack astronomically unlikely.

🎬 Watch & Learn

On semantic security & provable security

🧠 Test Yourself
09

Cryptanalysis

The art and science of breaking ciphers

? Why break your own cipher?

Cryptanalysis is the attacking half of cryptology — and it is how we learn which ciphers to trust. A cipher earns confidence only by surviving decades of the world's best cryptanalysts trying to break it. The attacks below also define the "threat models" that security definitions promise to resist.

A toolbox of attacks

  • Frequency analysis: count how often each letter appears — this instantly breaks simple substitution ciphers (in English, "E" is most common).
  • Brute force: try every key. Feasible against short keys, hopeless against a 128-bit one.
  • Differential & linear cryptanalysis: track how tiny input differences ripple through a block cipher — the benchmark every modern cipher must resist.
  • Meet-in-the-middle: why Double-DES is barely stronger than DES, so we use Triple-DES instead.
  • Side-channel attacks: ignore the math and measure the device — its timing, power draw or emissions — to leak the key.
Birthday attack: a collision in an n-bit hash needs only ~2n/2 work

The birthday bound

Because of the "birthday paradox," finding two inputs with the same hash takes roughly the square root of the naive effort. That is exactly why secure hashes need 256 bits: it drops the attacker's real work to a still-impossible 2128.

💡 Did you know? The first known systematic cryptanalysis — frequency analysis — was written down by the 9th-century Arab scholar Al-Kindi, over a thousand years before computers.

🎬 Watch & Learn

Computerphile · Cracking codes with frequency analysis

🧠 Test Yourself