Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Maths IA Poster: The RSA Encryption

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

Maths IA Poster: The RSA Encryption

August 14, 2023

Evan Luo

1. Introduction
1.1. Symmetric Encryption
In the modern world, we use Internet in our daily life. We use Internet to transfer message to others,
shopping online, etc. These things all require an important process: Encryption. Without encryption,
hackers can see the message you sent to your friends and even steal your money stored in the banks.
The traditional encryption method is to set a secret between two sides (the side here can be an orga-
nization, a person or a service) and use this secret to encrypt the data. Anyone who have this secret
can decrypt the data. This is called Symmetric Cryptography. However, this method has a defect:
the process of transferring the secret between two sides has to be secured, or else the encryption is
not safe.
For example, Alice want to send her credit card password to Bob on email secretly. First, she has to
send a secret to Bob through email, but this means that if someone intercepts this email, the encryption
will loss effectiveness.

Figure 1: Normal Symmetric Encryption.

1
Figure 2: Unsafe Symmetric Encryption.
If Alice wants to make the encryption effective, she has to transfer the secret offline or makes sure that
no one except Bob can get this secret. But this is pretty hard and not convenient.
Therefore, cryptographers create a new way of encryption: Asymmetric Encryption. And the rep-
resentative algorithm of this way is RSA.

1.2. Asymmetric Encryption


Different to symmetric encryption, asymmetric encryption uses two secrets to avoid the problems
mentioned before. These two secrets are called Public Key and Private Key.
Like their name, public key means that this key can be seen by anyone without security problems.
Private key cannot be seen by others, which means that only the owner can see the key. Here is an
example.
Alice learned asymmetric encryption now. She creates a pair of keys: 𝐴pub and 𝐴pri . Bob has a pair
of keys too. They are 𝐵pub and 𝐵pri . Bob first send his public key 𝐵pub to Alice via email. Then, Alice
uses 𝐵pub to encrypt her credit card password, and send the encrypted password to Bob. Now, Bob can
use his private key 𝐵pri to decrypt the password. Only if Bob leaks his private, the password can be
known by the third person.

2
Figure 3: The Asymmetric Encryption Process.
This is the key process of asymmetric encryption. Now we are going to talk about the RSA algorithm.

2. RSA Algorithm
2.1. Background Information
RSA is one of the oldest and the most widely used asymmetric encryption algorithm. The acronym
“RSA” comes from the surnames of Ron Rivest, Adi Shamir and Leonard Adleman, who publicly de-
scribed the algorithm in 1977. The security of RSA is based on the complexity of factoring the product
of two large prime numbers. The problem is called the Factoring Problem.

2.2. Encryption & Decryption Process


2.2.1. Public and Private Key Generation
Step 1: Calculate the Product of Two Large Prime Number
To generate the public and private key, first we need to randomly generate two large prime number 𝑝
and 𝑞, and calculate the product 𝑁 of them:
𝑁 =𝑝×𝑞 (1)

Step 2: Calculate 𝝋(𝑵 )


Then, we need to calculate 𝜑(𝑁 ), where 𝜑 is the Euler’s totient function.
Euler’s totient function In number theory, Euler’s totient function counts the positive integers up
to a given integer 𝑛 that are relatively prime to 𝑛.
According to 𝜑’s feature: If 𝑎, 𝑏 are coprime, then 𝜑(𝑎𝑏) = 𝜑(𝑎)𝜑(𝑏). So we can get 𝜑(𝑁 ) = 𝜑(𝑝)𝜑(𝑞).
Also, it is very obvious that if 𝑛 is a prime number, all of integers that less than 𝑛 are coprime with 𝑛,
which means that 𝜑(𝑛) = 𝑛 − 1.
Therefore, we can calculate 𝜑(𝑁 ) by the following formula:

3
𝜑(𝑁 ) = 𝜑(𝑝)𝜑(𝑞) = (𝑝 − 1)(𝑞 − 1) (2)

Step 3: Calculate the Modular Multiplicative Inverse of 𝒆 with Respcet To 𝝋(𝑵 )


The next step is to select an integer 𝑒 where 𝑒 < 𝜑(𝑁 ) and gcd(𝑒, 𝜑(𝑁 )) = 1. And then we calculate
the Modular Multiplicative Inverse 𝑑 of 𝑒 with respect to 𝜑(𝑁 ).
Modular Multiplicative Inverse A modular multiplicative inverse of an integer 𝑎 with respect
to the modulus 𝑚 is the 𝑏 satisfy the equation 𝑎−1 ≡ 𝑏 (mod 𝑛), which is equivalent to
𝑎𝑏 ≡ 1 (mod 𝑛)
According to the definition, 𝑑 satisfy the equation
𝑒𝑑 ≡ 1 (mod 𝜑(𝑁 )) (3)

To calculate 𝑑, we use Extended Euclidean Algorithm.


Extended Euclidean Algorithm An algorithm used to solve the integer solution of equation
𝑎𝑥 + 𝑏𝑦 = 𝑐.
We transform Equation 3 into the form of:
𝑒𝑑 − 𝑘𝜑(𝑁 ) = 1 (4)

Now the Equation 3 satisfies the form of extended euclidean algorithm. The problem has been changed
to solve 𝑑 and −𝑘 using the extended euclidean algorithm. The detailed process of the algorithm is too
complex, so here we don’t explain it.

Step 4: Destory Any History of 𝒑 and 𝒒 and Construct Public And Private Keys
The final step is to destory any history (logs of calculating the keys, etc.), and construct public and
private keys. The public key will be like (𝑁 , 𝑒) and the private key will be like (𝑁 , 𝑑).

2.2.2. Encryption
To encrypt a message, first we need to convert the message into a integer 𝑚, where
𝑚 < 𝑁 , gcd(𝑚, 𝑁 ) = 1. Then we use the formula below to encrypt the message:
𝑚𝑒 ≡ 𝑐 (mod 𝑁 ) (5)

which is equivalent to 𝑐 = 𝑚𝑒 mod 𝑁 , 𝑐 is the encrypted message.

2.2.3. Decryption
We use the 𝑑 to decrypt a message:

𝑐𝑑 ≡ 𝑚 (mod 𝑁 ) (6)

which is equivalent to 𝑚 = 𝑐𝑑 mod 𝑁


To be notice, 𝒎 𝐦𝐨𝐝 𝑵 should be in the range of [𝟎, 𝑵 ), which means that 𝑚 cannot be larger
than 𝑁 .

2.2.4. Proof
But why the encryp and decrypt equation is like that? We need to prove it.
According to Equation 5, we can get:

4
𝑐 = 𝑚𝑒 − 𝑘𝑛 (7)
By Replace 𝑐 in Equation 6, we get:

(𝑚𝑒 − 𝑘𝑛)𝑑 ≡ 𝑚 (mod 𝑁 ) (8)

which is equivalent to:

𝑚𝑒𝑑 ≡ 𝑚 (mod 𝑁 ) (9)

This is because if we we use the binomial theorem to expand (𝑚𝑒 − 𝑘𝑁 )𝑑 , it will be like this:
𝑑
𝑑
∑( )𝑚𝑒𝑘 (𝑘𝑁 )𝑑−𝑘 (10)
𝑘=0
𝑘

It is obvious that every term except the first term all contains 𝑘𝑁 , which means that they are all di-
visible by 𝑁 .
Now the problem is converted to proving Equation 9. But we have to make another conversion.
We can write Equation 3 in the form below:
𝑒𝑑 = ℎ𝜑(𝑁 ) + 1 (11)

Replace the 𝑒𝑑 in Equation 9:

𝑚ℎ𝜑(𝑁)+1 ≡ 𝑚 (mod 𝑁 ) (12)

Now the problem is to prove Equation 12. We have two kinds of situations.

Situation 1: 𝒎 and 𝑵 are Coprime


Here we need to use the Euler’s theorem.
Euler’s Theorem If 𝑎 and 𝑛 are coprime, then 𝑎𝜑(𝑁) ≡ 1 (mod 𝑛).
According to Euler’s theorem, we can get:

𝑚𝜑(𝑁) ≡ 1 (mod 𝑁 )
⇒ 𝑚ℎ𝜑(𝑁) ≡ 1ℎ (mod 𝑁 )
⇒ 𝑚ℎ𝜑(𝑁) ≡ 1 (mod 𝑁 ) (13)
ℎ𝜑(𝑁)
⇒𝑚 ⋅ 𝑚 ≡ 1 ⋅ 𝑚 (mod 𝑁 )
⇒ 𝑚ℎ𝜑(𝑁)+1 ≡ 𝑚 (mod 𝑁 )

Therefore, Equation 12 is correct.

Situation 2: 𝒎 and 𝑵 are not Coprime


Because 𝑚 and 𝑁 are not coprime, and 𝑁 = 𝑝𝑞, there must be a 𝑘 satisfy 𝑚 = 𝑘𝑝 or 𝑚 = 𝑘𝑞. Here
we assume that 𝑚 = 𝑘𝑝.
Because 𝑞 is prime, and 𝑞 is not 𝑘’s prime factor: If 𝑘 = 𝑙𝑞, then 𝑚 = 𝑘𝑝 = 𝑙𝑞𝑝 = 𝑙𝑁 > 𝑁 , which
contradicts with 𝑚 < 𝑁 ; 𝑘 and 𝑞 are coprime. In other words, 𝑚 and 𝑞 are coprime.
According to Euler’s theorem, we have:

5
𝑚𝜑(𝑞) ≡ 1 (mod 𝑞)
⇒ 𝑚ℎ𝜑(𝑞) ≡ 1 (mod 𝑞)
𝜑(𝑝)
⇒ (𝑚ℎ𝜑(𝑞) ) ≡ 1 (mod 𝑞) (14)
⇒ 𝑚ℎ𝜑(𝑁) ≡ 1 (mod 𝑞)
⇒ 𝑚ℎ𝜑(𝑁)+1 ≡ 𝑚 (mod 𝑞)

Replace ℎ𝜑(𝑁 ) + 1 with Equation 11:

𝑚𝑒𝑑 ≡ 𝑚 (mod 𝑞) (15)

Replace 𝑚 with 𝑚 = 𝑘𝑝:

(𝑘𝑝)𝑒𝑑 ≡ 𝑘𝑝 (mod 𝑞) (16)

which is equivalent to:

(𝑘𝑝)𝑒𝑑 = 𝑡′ 𝑝𝑞 + 𝑘𝑝 (17)

Divide 𝑝 from both sides, we can see that the LHS is divisible by 𝑝. Therefore, the RHS 𝑡 𝑝𝑞 + 𝑝 is an
integer.
𝑡
Because 𝑝 and 𝑞 are coprime, 𝑝
has to be an integer, which means that 𝑡 ∣ 𝑝. Hence, we have:
𝑡 = 𝑡′ 𝑝 (18)

Replace 𝑡 in Equation 17:

(𝑘𝑝)𝑒𝑑 = 𝑡′ 𝑝𝑞 + 𝑘𝑝 (19)

Replace 𝑘𝑝 and 𝑝𝑞:

𝑚𝑒𝑑 = 𝑡′ 𝑁 + 𝑚
⇒ 𝑚𝑒𝑑 ≡ 𝑚 (mod 𝑁 ) (20)
𝑑
⇒ 𝑐 ≡ 𝑚 (mod 𝑁 )

Hence, the decryption formula is correct.

You might also like