Bite-Sized Mathematics for Computer Science

Notes on MIT's 6.042J

Eda Eren
Table of Contents

Introduction

Prerequisites & Resources

Unit 1: Proofs

00. Introduction to Proofs

01. (Two) Proof Methods

02. The Well Ordering Principle

03. Logic & Propositions

04. Quantifiers and Predicate Logic

05. Sets

06. Binary Relations

07. Induction

08. State Machines — Invariants

09. Recursive Definitions

10. Infinite Sets

Unit 2: Structures

11. GCDs

12. Congruences

13. Euler's Theorem

15. Digraphs: Walks and Paths

16. Directed Acyclic Graphs

17. Partial Orders and Equivalence

18. Degrees & Isomorphism

19. Coloring & Connectivity

20. Trees

21. Stable Matching

Unit 3: Counting

22. Sums & Products

23. Asymptotics

24. Counting with Bijections

25. Repetitions & Binomial Theorem

26. Pigeonhole Principle, Inclusion-Exclusion

Unit 4: Probability

27. Intro to Discrete Probability

28. Conditional Probability

29. Independence & Causality

30. Random Variables, Density Functions

31. Expectation

32. Deviation: Markov & Chebyshev Bounds

33. Sampling & Confidence

34. Random Walks & PageRank

RSA Encryption

In A Mathematician's Apology, G. H. Hardy wrote:

[Number theorists] may be justified in rejoicing that there is one science, at any rate, and that their own, whose very remoteness from ordinary human activities should keep it gentle and clean.

How wrong he was.

Number theory is the core of modern cryptography today, which is central to all kinds of online activity.

RSA, first proposed by Ronald Rivest, Adi Shamir, and Leonard Adleman in 1977, is a cryptosystem that also—you guessed it—relies on number theory.


So, we have two players: a sender and a receiver.
The receiver has two keys: public and private. The sender encrypts their message with the public key of the receiver, which is obviously public, and the receiver can decrypt the message using their private key which is known only to the receiver. The beauty of it is that the sender and the receiver don't need to agree on a key beforehand.

Let's see how the receiver can generate public and private keys.

First, generate two primes, pp and qq. (pp and qq tend to be, you know, As Random As Possible and Many Digits Long).
Multiply pp and qq to get nn. In other words, let n=pqn = pq.
Then, find an integer ee such that gcd(e, (p1)(q1))=1\text{gcd}(e, \ (p - 1)(q - 1)) = 1, that is, ee is relatively prime to (p1)(q1)(p - 1)(q - 1). *
The pair (e, n)(e, \ n) is the public key which can be distributed.
Because ee is relatively prime to (p1)(q1)(p - 1)(q - 1), it has an inverse (e1e^{-1}) in Z(p1)(q1)\mathbb{Z}^*_{(p - 1)(q - 1)}, let's call it dd. **
dd is the private key that the receiver keeps hidden.

* Remember Euler's totient function? (ϕ(pq)=(p1)(q1)\phi(pq) = (p - 1)(q - 1) for primes pqp \neq q.)
** Remember that Zn\mathbb{Z}^*_n is the set of numbers in [0, n)[0, \ n) that are relatively prime to nn.

If you knew what pp and qq are, it'd be easy to figure out what the private key is. Well, the thing with one-way functions is that they are easy to compute but hard to invert. So, even if it's easy to compute the product of pp and qq to get nn, it's hard to factor nn to get pp and qq.


What about the sender?

First, the message mm that they are going to send to the receiver has to be in the range [1,n)[1, n), which means it can be represented by a Many Digits Long number.

Because the sender knows the receiver's public key, they need to raise the message mm to ee in Zn\mathbb{Z}_n (has to be mod(n)\text{mod}(n)) to get the encoded message m^\hat{m}:

m^=me  (Zn)\hat{m} = m^e \ \ (\mathbb{Z}_n)

Then, how does the receiver decode m^\hat{m}?
They just need to raise m^\hat{m} to their private key dd in Zn\mathbb{Z}_n (again, mod(n)\text{mod}(n)) to get the decoded message:

m=m^d  (Zn)m = \hat{m}^d \ \ (\mathbb{Z}_n)