Skip to content
The Lumenary

Each worksheet prints cleanly on A4 or Letter. Answer keys are on a separate page.

The Lumenary · Early undergraduate

Cryptography

Name: ______________________

Date: ______________________

You will learn to

  • Implement RSA key generation, encryption and decryption, and prove that decryption works for every message using Fermat's little theorem and the Chinese remainder theorem
  • Compute modular powers by repeated squaring and prove that it uses O(log⁡e)O(\log e) multiplications
  • Carry out a Diffie–Hellman key exchange and explain its reliance on the difficulty of discrete logarithms
  • Prove that the one-time pad has perfect secrecy, and explain why practical systems rely instead on unproved hardness assumptions
  • Explain why textbook RSA is unsafe in practice and why encryption alone does not guarantee authenticity
  1. 1.

    A toy RSA public key is (n,e)=(33,3)(n, e) = (33, 3), where 33=3⋅1133 = 3 \cdot 11. Encrypt the message m=5m = 5: compute c=me mod nc = m^e \bmod n.

  2. 2.

    For the toy key p=5p = 5, q=11q = 11, n=55n = 55 and e=3e = 3, find the private exponent dd with 0<d<400 < d < 40 and ed≡1(mod(p−1)(q−1))ed \equiv 1 \pmod{(p - 1)(q - 1)}.

  3. 3.

    With the key n=55n = 55, e=3e = 3, d=27d = 27, a ciphertext c=13c = 13 arrives. Decrypt it: find m=cd mod 55m = c^d \bmod 55. (Hint: you can check your answer by encrypting it.)

  4. 4.

    Ama and Bolat use Diffie–Hellman with p=29p = 29 and g=2g = 2. Ama's secret is a=5a = 5, Bolat's is b=12b = 12. Ama sends A=25 mod 29=3A = 2^5 \bmod 29 = 3 and Bolat sends B=212 mod 29=7B = 2^{12} \bmod 29 = 7. What shared key do they compute?

  5. 5.

    An attacker knows the public key (n,e)(n, e) of an RSA user. Which additional pieces of information would let the attacker compute the private exponent dd efficiently, with known methods? (Choose all that apply.)

    • A.the factors pp and qq of nn
    • B.the number φ(n)=(p−1)(q−1)\varphi(n) = (p - 1)(q - 1)
    • C.one message mm together with its ciphertext me mod nm^e \bmod n
    • D.nothing more: dd can be computed from nn and ee by repeated squaring
  6. 6.

    Textbook RSA with e=3e = 3 and a 2048-bit modulus nn is used to send a 100-bit number mm, as c=m3 mod nc = m^3 \bmod n. What can an eavesdropper do?

    • A.Recover mm as the ordinary integer cube root of cc
    • B.Nothing, because recovering mm requires factoring nn
    • C.Compute dd from cc by Euclid's algorithm
    • D.Use Fermat's little theorem modulo nn to undo the cube
  7. 7.

    Which Lean statement is a true formalisation of RSA correctness, as proved in the lesson?

    • A.theorem t {p q e d : ℕ} (hp : p.Prime) (hq : q.Prime) (hpq : p ≠ q) (hed : e * d ≡ 1 [MOD (p - 1) * (q - 1)]) (m : ℕ) : (m ^ e) ^ d ≡ m [MOD p * q]
    • B.theorem t {p q e d : ℕ} (hp : p.Prime) (hq : q.Prime) (hed : e * d ≡ 1 [MOD (p - 1) * (q - 1)]) (m : ℕ) : (m ^ e) ^ d ≡ m [MOD p * q]
    • C.theorem t {p q e d : ℕ} (hp : p.Prime) (hq : q.Prime) (hpq : p ≠ q) (m : ℕ) : (m ^ e) ^ d ≡ m [MOD p * q]
    • D.theorem t (n e : ℕ) : ¬ ∃ d, ∀ m, (m ^ e) ^ d ≡ m [MOD n]
  8. 8.

    Implement pow_mod(b, e, n) by repeated squaring without using Python's three-argument pow: return be mod nb^e \bmod n. It must handle exponents with hundreds of digits instantly.

    Computational — Practice

Code: Apache-2.0 · Content: CC BY-SA 4.0