We discuss the problem of sending a message secretly over the internet. Suppose the original message is a sequence xx, the encrypted message is yy.

XOR Encryption

One solution is to via the XOR operation. Suppose there is a key kk that is known both to the sender the receiver. Given an integer n∈Nn \in \mathbb{N}, denote (n)2(n)_2 its binary representation.

Sender Encryption. $ (y)_2 = (x)_2 \oplus (k)_2. $

Receiver Decryption. $ (x)_2 = (y)_2 \oplus (k)_2. $

Analysis

Given xx with length nn, if kk is sampled uniformly at random from {0,1}n\{0, 1\}^n, then (y)2(y)_2 is a sequence uniformly at random from {0,1}n\{0, 1\}^n. If the message is sent only one time, the eavesdropper can't get more information about xx after seeing yy.

Two drawbacks exists.

  1. How can the sender exchange the key kk with the receiver without meeting each other?

  2. If the many messages are sent, there are frequency pattern associated with yy, making it breakable.

RSA Encryption

RSA encryption algorithm overcomes the first issue by generating two keys for the receiver: the secrete key and the public key. The public key is distributed across the internet. The sender encrypts the message xx with the public key. Only the receiver who has the secret key can decrypt the message. The mathematics behind is explained as follows.

Question to ponder: can we attack RSA by the frequency pattern?

Generation

First generate two prime number p,qp, q and let N=pqN = pq. Further, we find a integer ee, such that

  1. ee is coprime to (p−1)(q−1)(p - 1)(q - 1), i.e., ∃d\exists d, such thated≡1(mod(p−1)(q−1)). ed \equiv 1 \pmod{(p - 1)(q - 1)}.
  2. e≠pe \neq p, e≠qe \neq q.

Question to ponder: does such ee exists?

Answer: YES. There are Ω((p−1)(q−1)log⁡(p−1)(q−1)−(p−1)(q−1)log⁡(p−1)(q−1))\Omega \left( \frac{(p - 1)(q - 1) }{ \log (p - 1)(q - 1) } - \frac{ \sqrt{ (p - 1)(q - 1) } }{ \log \sqrt { (p - 1)(q - 1) } } \right) prime numbers in ((p−1)(q−1),(p−1)(q−1))\left( \sqrt{(p - 1)(q - 1)}, (p - 1)(q - 1) \right). Find three distinct primes within this range, denoted as p1,p2,p3p_1, p_2, p_3. Then p1⋅p2⋅p3>(p−1)(q−1)p_1 \cdot p_2 \cdot p_3 > (p - 1) (q - 1), so at least one of them is not a prime factors of (q−1)(p−1)(q - 1)(p - 1).

Encryption and Decryption

Release the pair as public key:

(N,e). (N, e).

And keep in secrete the triple as private key:

(p,q,d). (p, q, d).

The algorithm for encryption and decryption is as follows:

Sender Encryption. $ y \equiv x^e \pmod N. $

Receiver Decryption. $ x \equiv y^d \pmod N. $

To prove the correctness of the algorithm, we have

Theorem $ x^{e d} \equiv x \pmod N. $

Proof.

Since ed≡1(mod(p−1)(q−1))ed \equiv 1 \pmod{(p - 1)(q - 1)}, there exists some k∈Nk \in \mathbb{N}, s.t., ed=k(p−1)(q−1)+1e d = k (p - 1)(q - 1) + 1. Hence,

m≡⋅xed(modN)≡xk⋅(p−1)⋅(q−1)+1(modN). m \stackrel{\cdot}{\equiv} x^{ed} \pmod{N} \equiv x^{k \cdot (p - 1) \cdot (q - 1) + 1} \pmod{N}.

By Fermat's Little Theorem,

m≡x(modp),  and  m≡x(modq). m \equiv x \pmod p,\, \text{ and }\, m \equiv x \pmod q.

Or equivalent, both pp and qq divides m−xm - x:

m−x≡0(modp),  and  m−x≡0(modq). m - x \equiv 0 \pmod p,\, \text{ and }\, m - x \equiv 0 \pmod q.

It follows that m−xm - x is a common multiple of pp and qq, and therefore, m−xm - x is divided by the least common multiple of pp and qq, i.e., N∣(m−x)N | (m - x).

Hence m≡x(modN)m \equiv x \pmod N.

□\square