Skip to content
Infinitesimal Dynamics home
Notebook: 0 XP

Cryptography / Public-key cryptography

RSA

Public-key encryption and signatures built from Euler’s theorem and the difficulty of factoring.

3 min read · 2 sections · 2 checks

Contents 3 sections
  1. §1Building keys
  2. §2A toy example
  3. ?Check yourself

By the end you can

  • Generate a toy RSA key pair
  • Encrypt, decrypt and sign with RSA
  • Explain why RSA is believed secure

Helps to know: Diffie–Hellman Key Exchange

§1Building keys

  1. Choose two large primes p,qp, q and set n=pqn = pq.
  2. Compute φ(n)=(p−1)(q−1)\varphi(n) = (p - 1)(q - 1).
  3. Choose ee with gcd⁡(e,φ(n))=1\gcd(e, \varphi(n)) = 1; commonly e=65537e = 65537.
  4. Compute d=e−1 mod φ(n)d = e^{-1} \bmod \varphi(n).
  5. Publish (n,e)(n, e); keep dd secret.
c=me mod nm=cd mod nc = m^e \bmod n \qquad m = c^d \bmod n

Decryption works because ed=1+kφ(n)ed = 1 + k\varphi(n), so med=m⋅(mφ(n))k≡mm^{ed} = m \cdot (m^{\varphi(n)})^k \equiv m by Euler’s theorem.

§2A toy example

Example 1p=5p = 5, q=11q = 11

  1. n=55n = 55, φ(n)=40\varphi(n) = 40.

Check yourself

  1. Q1
    With p=3p = 3 and q=11q = 11, φ(n)=\varphi(n) =
  2. Q2
    Factoring nn would let an attacker…