Number Theory and Cryptography
12.1 Public-Key Cryptography
Section titled “12.1 Public-Key Cryptography”Classical ciphers share one key: anyone who can encrypt can decrypt. Public-key cryptography splits the key: a public key (published, used to encrypt or verify) and a private key (secret, used to decrypt or sign). The trick is a one-way function with a trapdoor: easy to compute in one direction, computationally infeasible to invert without secret knowledge.
Number theory supplies both halves:
- Easy: multiply two large primes; compute modular powers by repeated squaring.
- Hard: factor a 600-digit composite; compute discrete logarithms modulo a large prime.
12.2 RSA
Section titled “12.2 RSA”Setup. Choose two large distinct primes (each hundreds of digits). Let and . Choose with ; compute the private exponent with (extended Euclid). Public key: . Private key: .
Encryption of a message (): .
Decryption: .
Why it works. Euler’s theorem: since (for coprime to ),
because implies and . (A sharper proof works for all using and and CRT.)
Worked example (toy size). , , , , , (since ). Encrypt : . Decrypt: ✓ (by repeated squaring: 12 squarings and a handful of multiplications).
Security. Recovering from is as hard as factoring (there are reductions both ways for proper key generation). All classical attacks reduce to factoring; 2048-bit is the current floor. Pitfall: shared primes, small without padding, and deterministic encryption are the standard exam criticisms.
12.3 Diffie–Hellman Key Exchange
Section titled “12.3 Diffie–Hellman Key Exchange”Public: a large prime and a primitive root modulo .
- Alice chooses secret ; publishes .
- Bob chooses secret ; publishes .
- Shared secret: Alice computes ; Bob computes (both reduced mod ).
An eavesdropper sees but must solve the discrete logarithm problem to get or ; infeasible for 2048-bit .
Worked example. , (primitive root mod 23). Alice: , . Bob: , . Shared: ✓.
12.4 ElGamal Encryption
Section titled “12.4 ElGamal Encryption”Public: as above and Alice’s public key . To encrypt to Alice: pick ephemeral , send and . Alice decrypts with her secret :
using . Security rests on the Diffie–Hellman problem.
12.5 Euler, Fermat and Practical Detail
Section titled “12.5 Euler, Fermat and Practical Detail”- Repeated squaring computes in multiplications; the reason large exponents are feasible.
- guarantees exists (multiplicative inverse modulo , extended Euclid; see Congruences).
- Decryption works for all (not just coprime ones) when : check mod and mod separately, then CRT.
12.6 Common Pitfalls
Section titled “12.6 Common Pitfalls”- requires : with , , not .
- Never publish or : knowing is equivalent to knowing and .
- Textbook RSA is deterministic and malleable: real systems use randomised padding (OAEP); state this in “criticise the scheme” questions.
- Diffie–Hellman without authentication is a man-in-the-middle target: the fix is signatures (RSA or ElGamal signatures), not a change of group.
See Also
Section titled “See Also”- Fermat, Euler and Wilson Theorems
- Primitive Roots and Discrete Logarithms
- Linear Congruences and the Chinese Remainder Theorem
A full exam question walks the entire key generation: choose primes, compute and , pick and invert it, encrypt a small message by repeated squaring, decrypt, and then criticise the scheme. Practise each stage to the point where repeated squaring is mechanical.
The standard criticism list: deterministic encryption leaks equality of plaintexts; small decryption exponents fall to Wiener’s continued-fraction attack (the continued-fraction page is the natural companion); shared factors between two public moduli break both keys; the factoring is a single gcd.