Public-key cryptography: the maths
Trapdoor one-way functions: multiplication and factoring, modular exponentiation and the discrete logarithm.
Public-key cryptography rests on trapdoor one-way functions: easy to compute in one direction, extremely hard to invert, unless you know a secret piece of information — the trapdoor — that makes inversion easy.
| Problem | Easy direction | Hard direction | Used by |
|---|---|---|---|
| Factoring | Multiplying two large primes | Recovering the primes from the product | RSA |
| Discrete logarithm | Computing g^x mod p | Recovering x from g^x mod p | Diffie-Hellman, DSA signatures |
| Elliptic-curve discrete logarithm | Adding a point to itself k times | Recovering k from the result | ECDH, ECDSA, Ed25519 |
An example of one-wayness
Computing 7^3 mod 11 is immediate: 343 divided by 11 leaves remainder 2. But if you are only told that 7^x mod 11 = 2, finding x means trying values one by one. With small numbers it takes a moment; with numbers hundreds of digits long, no known method does it in reasonable time.
Public-key cryptography: worked example
A digital signature with small numbers, using the example RSA keys, to see how private and public keys work together.
The pages of this topic
Back to the overviewPublic-key cryptography: how it works
The open padlock as a metaphor, encryption with the public key, signing with the private key and hybrid cryptography.
Public-key cryptography: history
From the secret insights of Britain’s GCHQ to Diffie and Hellman’s paper, from RSA to elliptic curves and certificate infrastructures.
Public-key cryptography: weaknesses and attacks
The man-in-the-middle attack, weak keys, side channels and the quantum threat: where public-key cryptography can fail.
Public-key cryptography today
Where public-key cryptography is used every day: HTTPS, digital signatures, messaging, passkeys, cryptocurrencies, software updates.
Public-key cryptography: try it yourself
Exercises on modular exponentiation, one-wayness and verifying a signature, with solutions.
Public-key cryptography: frequently asked questions
Short answers to the most common doubts about public-key cryptography.