We discuss the problem of sending a message secretly over the internet. Suppose the original message is a sequence , the encrypted message is .
XOR Encryption
One solution is to via the XOR operation. Suppose there is a key that is known both to the sender the receiver. Given an integer , denote its binary representation.
Sender Encryption. $ (y)_2 = (x)_2 \oplus (k)_2. $
Receiver Decryption. $ (x)_2 = (y)_2 \oplus (k)_2. $
Analysis
Given with length , if is sampled uniformly at random from , then is a sequence uniformly at random from . If the message is sent only one time, the eavesdropper can't get more information about after seeing .
Two drawbacks exists.
-
How can the sender exchange the key with the receiver without meeting each other?
-
If the many messages are sent, there are frequency pattern associated with , 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 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 and let . Further, we find a integer , such that
- is coprime to , i.e., , such that
- , .
Question to ponder: does such exists?
Answer: YES. There are prime numbers in . Find three distinct primes within this range, denoted as . Then , so at least one of them is not a prime factors of .
Encryption and Decryption
Release the pair as public key:
And keep in secrete the triple as private key:
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 , there exists some , s.t., . Hence,
By Fermat's Little Theorem,
Or equivalent, both and divides :
It follows that is a common multiple of and , and therefore, is divided by the least common multiple of and , i.e., .
Hence .