CS285 · Chapter 4 · Annotated SlidesNumber Theory and Cryptography
Original
Overview

Number Theory and Cryptography

Divisibility, primes and the Fundamental Theorem of Arithmetic, GCD and LCM, the division algorithm, mod and congruences, then classical ciphers (Caesar, shift, affine), public-key cryptography with RSA, and the Diffie–Hellman key exchange.

How to read this page

Every original slide is shown unchanged. Yellow marks on a slide point to a numbered note: hover or tap a mark to jump to its note, and hover a note to see its marks. Questions tagged Past exam appeared on a real paper; Prediction questions are likely angles, not confirmed. Pick an answer to each question: a wrong pick tells you why it is wrong, so you can try again.

All 84 slides
  1. 1 Slide 1
  2. 2 4.1 Divisibility and Modular Arithmetic
  3. 3 The Integers & Division
  4. 4 Divisors Examples
  5. 5 Divisors Examples
  6. 6 Facts: The Divides Relation
  7. 7 Composite & Prime Numbers
  8. 8 Fundamental Theorem of Arithmetic
  9. 9 Theorem
  10. 10 Prime Factorization Technique
  11. 11 Prime Factorization Examples
  12. 12 Slide 12
  13. 13 Primary Testing Example
  14. 14 Greatest Common Division (GCD)
  15. 15 2 Ways to find GCD
  16. 16 Slide 16
  17. 17 Slide 17
  18. 18 Greatest Common Division
  19. 19 Slide 19
  20. 20 Greatest Common Division Relatively Prime
  21. 21 Greatest Common Division Relatively Prime
  22. 22 Least Common Multiple
  23. 23 Slide 23
  24. 24 Division
  25. 25 The Division “Algorithm”
  26. 26 Examples
  27. 27 Solutions
  28. 28 mod Function Start Here
  29. 29 mod Function
  30. 30 Question
  31. 31 Question
  32. 32 Modular Congruence
  33. 33 Examples
  34. 34 Useful Congruence Theorems
  35. 35 Ex.:
  36. 36 Slide 36
  37. 37 Section Summary
  38. 38 Why Cryptography
  39. 39 Slide 39
  40. 40 Symmetric Encryption
  41. 41 Symmetric Encryption
  42. 42 Caesar Cipher
  43. 43 Caesar cipher
  44. 44 Caesar Cipher
  45. 45 Caesar Cipher
  46. 46 Shift Cipher
  47. 47 Shift Cipher
  48. 48 Shift Cipher
  49. 49 Shift Cipher
  50. 50 Affine Ciphers
  51. 51 Cryptanalysis of Affine Ciphers
  52. 52 Cryptosystems
  53. 53 Cryptosystems
  54. 54 Slide 54
  55. 55 Public Key Cryptography
  56. 56 Clifford Cocks
  57. 57 The RSA Cryptosystem
  58. 58 Slide 58
  59. 59 Slide 59
  60. 60 The RSA Cryptosystem
  61. 61 RSA algorithm explanation -step by step example
  62. 62 Continue...
  63. 63 Continue...
  64. 64 Example
  65. 65 RSA Encryption
  66. 66 RSA Encryption- example
  67. 67 RSA Decryption
  68. 68 RSA Decryption- example
  69. 69 Slide 69
  70. 70 Slide 70
  71. 71 Slide 71
  72. 72 Slide 72
  73. 73 Slide 73
  74. 74 Slide 74
  75. 75 Diffie-Hellman
  76. 76 Diffie Helman Step by Step
  77. 77 Diffie Helman Step by Step- Cont
  78. 78 Slide 78
  79. 79 Slide 79
  80. 80 Slide 80
  81. 81 Slide 81
  82. 82 Cryptographic Protocols: Key Exchange
  83. 83 Cryptographic Protocols: Digital Signatures
  84. 84 Cryptographic Protocols: Digital Signatures
Slide 1 / 84

Slide 1

Slide 1: Slide 1
Slide 2 / 84

4.1 Divisibility and Modular Arithmetic

Slide 2: 4.1 Divisibility and Modular Arithmetic
Slide 3 / 84

The Integers & Division

Slide 3: The Integers & Division

Exam angle

PredictionQ1

3 | 12 and 12 | 3.

Slide 4 / 84

Divisors Examples

Slide 4: Divisors Examples
Slide 5 / 84

Divisors Examples

Slide 5: Divisors Examples
Slide 6 / 84

Facts: The Divides Relation

Slide 6: Facts: The Divides Relation

Notes

  1. If a | b and a | c then a | (b + c); if a | b then a | bc; if a | b and b | c then a | c.

Slide 7 / 84

Composite & Prime Numbers

Slide 7: Composite & Prime Numbers

Notes

  1. Prime: integer > 1 whose only positive divisors are 1 and itself. 1 is NOT prime.

Slide 8 / 84

Fundamental Theorem of Arithmetic

Slide 8: Fundamental Theorem of Arithmetic
Slide 9 / 84

Theorem

Slide 9: Theorem

Exam angle

PredictionQ1

To show 101 is prime it is enough to test divisibility by primes up to:

Slide 10 / 84

Prime Factorization Technique

Slide 10: Prime Factorization Technique
Slide 11 / 84

Prime Factorization Examples

Slide 11: Prime Factorization Examples
Slide 12 / 84

Slide 12

Slide 12: Slide 12
Slide 13 / 84

Primary Testing Example

Slide 13: Primary Testing Example
Slide 14 / 84

Greatest Common Division (GCD)

Slide 14: Greatest Common Division (GCD)

Notes

  1. gcd(a, b): largest integer dividing both. Relatively prime when gcd = 1.

Slide 15 / 84

2 Ways to find GCD

Slide 15: 2 Ways to find GCD

Notes

  1. gcd via prime factorizations: take the MIN power of each prime. lcm: take the MAX power.

  2. gcd(a, b)·lcm(a, b) = a·b.

Exam angle

PredictionQ1

gcd(120, 500) =

PredictionQ2

If gcd(a, b) = 6 and ab = 360, lcm(a, b) =

Slide 16 / 84

Slide 16

Slide 16: Slide 16
Slide 17 / 84

Slide 17

Slide 17: Slide 17
Slide 18 / 84

Greatest Common Division

Slide 18: Greatest Common Division
Slide 19 / 84

Slide 19

Slide 19: Slide 19
Slide 20 / 84

Greatest Common Division Relatively Prime

Slide 20: Greatest Common Division Relatively Prime

Notes

  1. Pairwise relatively prime: every pair has gcd 1.

Slide 21 / 84

Greatest Common Division Relatively Prime

Slide 21: Greatest Common Division Relatively Prime
Slide 22 / 84

Least Common Multiple

Slide 22: Least Common Multiple
Slide 23 / 84

Slide 23

Slide 23: Slide 23
Slide 24 / 84

Division

Slide 24: Division
Slide 25 / 84

The Division “Algorithm”

Slide 25: The Division “Algorithm”

Notes

  1. Division algorithm: a = dq + r with 0 ≤ r < d; q = a div d, r = a mod d.

  2. Trap The remainder is never negative: −11 div 3 = −4, −11 mod 3 = 1 (−11 = 3·(−4) + 1).

Exam angle

PredictionQ1

−11 mod 3 =

Slide 26 / 84

Examples

Slide 26: Examples
Slide 27 / 84

Solutions

Slide 27: Solutions
Slide 28 / 84

mod Function Start Here

Slide 28: mod Function Start Here
Slide 29 / 84

mod Function

Slide 29: mod Function
Slide 30 / 84

Question

Slide 30: Question
Slide 31 / 84

Question

Slide 31: Question
Slide 32 / 84

Modular Congruence

Slide 32: Modular Congruence

Notes

  1. a ≡ b (mod m) when m | (a − b), i.e. a mod m = b mod m.

Exam angle

PredictionQ1

17 ≡ 5 (mod 6).

Slide 33 / 84

Examples

Slide 33: Examples
Slide 34 / 84

Useful Congruence Theorems

Slide 34: Useful Congruence Theorems

Notes

  1. If a ≡ b and c ≡ d (mod m) then a + c ≡ b + d and ac ≡ bd (mod m).

Slide 35 / 84

Ex.:

Slide 35: Ex.:
Slide 36 / 84

Slide 36

Slide 36: Slide 36
Slide 37 / 84

Section Summary

Slide 37: Section Summary
Slide 38 / 84

Why Cryptography

Slide 38: Why Cryptography
Slide 39 / 84

Slide 39

Slide 39: Slide 39
Slide 40 / 84

Symmetric Encryption

Slide 40: Symmetric Encryption
Slide 41 / 84

Symmetric Encryption

Slide 41: Symmetric Encryption
Slide 42 / 84

Caesar Cipher

Slide 42: Caesar Cipher

Exam angle

PredictionQ1

Caesar (shift 3) encrypts "HI" as:

Slide 43 / 84

Caesar cipher

Slide 43: Caesar cipher
Slide 44 / 84

Caesar Cipher

Slide 44: Caesar Cipher
Slide 45 / 84

Caesar Cipher

Slide 45: Caesar Cipher
Slide 46 / 84

Shift Cipher

Slide 46: Shift Cipher
Slide 47 / 84

Shift Cipher

Slide 47: Shift Cipher
Slide 48 / 84

Shift Cipher

Slide 48: Shift Cipher
Slide 49 / 84

Shift Cipher

Slide 49: Shift Cipher
Slide 50 / 84

Affine Ciphers

Slide 50: Affine Ciphers

Exam angle

PredictionQ1

In an affine cipher f(p) = (ap + b) mod 26, a must satisfy:

Slide 51 / 84

Cryptanalysis of Affine Ciphers

Slide 51: Cryptanalysis of Affine Ciphers
Slide 52 / 84

Cryptosystems

Slide 52: Cryptosystems
Slide 53 / 84

Cryptosystems

Slide 53: Cryptosystems
Slide 54 / 84

Slide 54

Slide 54: Slide 54
Slide 55 / 84

Public Key Cryptography

Slide 55: Public Key Cryptography
Slide 56 / 84

Clifford Cocks

Slide 56: Clifford Cocks
Slide 57 / 84

The RSA Cryptosystem

Slide 57: The RSA Cryptosystem

Notes

  1. RSA: n = pq, choose e with gcd(e, (p−1)(q−1)) = 1, d = e⁻¹ mod (p−1)(q−1).

Slide 58 / 84

Slide 58

Slide 58: Slide 58
Slide 59 / 84

Slide 59

Slide 59: Slide 59
Slide 60 / 84

The RSA Cryptosystem

Slide 60: The RSA Cryptosystem
Slide 61 / 84

RSA algorithm explanation -step by step example

Slide 61: RSA algorithm explanation -step by step example
Slide 62 / 84

Continue...

Slide 62: Continue...
Slide 63 / 84

Continue...

Slide 63: Continue...
Slide 64 / 84

Example

Slide 64: Example
Slide 65 / 84

RSA Encryption

Slide 65: RSA Encryption
Slide 66 / 84

RSA Encryption- example

Slide 66: RSA Encryption- example
Slide 67 / 84

RSA Decryption

Slide 67: RSA Decryption

Exam angle

PredictionQ1

RSA with p = 3, q = 11, e = 3. Find n, φ, and d.

Compare with the model answer

n = 33, φ = (p−1)(q−1) = 20. d is the inverse of 3 mod 20: 3·7 = 21 ≡ 1, so d = 7.

PredictionQ2

In RSA, which key is kept secret?

Slide 68 / 84

RSA Decryption- example

Slide 68: RSA Decryption- example
Slide 69 / 84

Slide 69

Slide 69: Slide 69
Slide 70 / 84

Slide 70

Slide 70: Slide 70
Slide 71 / 84

Slide 71

Slide 71: Slide 71
Slide 72 / 84

Slide 72

Slide 72: Slide 72
Slide 73 / 84

Slide 73

Slide 73: Slide 73
Slide 74 / 84

Slide 74

Slide 74: Slide 74
Slide 75 / 84

Diffie-Hellman

Slide 75: Diffie-Hellman

Notes

  1. Diffie–Hellman: agree on prime p and base g; Alice sends gᵃ mod p, Bob sends gᵇ mod p; both compute the shared key gᵃᵇ mod p.

Exam angle

PredictionQ1

p = 23, g = 5, a = 6, b = 15. Alice sends:

Slide 76 / 84

Diffie Helman Step by Step

Slide 76: Diffie Helman Step by Step
Slide 77 / 84

Diffie Helman Step by Step- Cont

Slide 77: Diffie Helman Step by Step- Cont
Slide 78 / 84

Slide 78

Slide 78: Slide 78
Slide 79 / 84

Slide 79

Slide 79: Slide 79
Slide 80 / 84

Slide 80

Slide 80: Slide 80
Slide 81 / 84

Slide 81

Slide 81: Slide 81
Slide 82 / 84

Cryptographic Protocols: Key Exchange

Slide 82: Cryptographic Protocols: Key Exchange
Slide 83 / 84

Cryptographic Protocols: Digital Signatures

Slide 83: Cryptographic Protocols: Digital Signatures
Slide 84 / 84

Cryptographic Protocols: Digital Signatures

Slide 84: Cryptographic Protocols: Digital Signatures