0% found this document useful (0 votes)
81 views4 pages

RSA Encryption and Decryption Examples

Uploaded by

Niharika Dubey
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
81 views4 pages

RSA Encryption and Decryption Examples

Uploaded by

Niharika Dubey
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Qu.

Perform encryption and decryption using the RSA algorithm for the following:
1. p=3; q=11; e=7; M=5
Answer:
n = p * q = 3 * 11 = 33
f(n) = (p-1) * (q-1) = 2 * 10 = 20
Now, we need to compute d = e-1 mod f(n) by using backward substitution of GCD
algorithm:
According to GCD:
20 = 7 * 2 + 6
7=6*1+1
6=1*6+0
Therefore, we have:
1=7–6
= 7 – (20 – 7 * 2)
= 7 – 20 + 7 * 2
= -20 + 7 * 3
-1 -1
Hence, we get d = e mod f(n) = e mod 20 = 3 mod 30 = 3
So, the public key is {7, 33} and the private key is {3, 33}, RSA encryption and
decryption is following:
Encryption Decryption
Plaintext ciphertext Plaintext
5 14 5

57 Mod 33= 14 143 Mod 33 = 5

PU= (7, 33) PR= (3, 33)


2. p=5; q=11; e=3; M=9
Answer:
n = p * q = 5 * 11 = 55
f(n) = (p-1) * (q-1) = 4 * 10 = 40
Now, we need to compute d = e-1 mod f(n) by using backward substitution of GCD
algorithm:
According to GCD:
40 = 3 * 13 + 1
13 = 1 * 13 + 0
Therefore, we have:
1 = 40 – 3 * 13
Hence, we get d = e mod f(n) = e mod 40 = -13 mod 40 = (27 – 40) mod 40 = 27
-1 -1

So, the public key is {3, 55} and the private key is {27, 55}, RSA encryption and
decryption is following:
Encryption Decryption
Plaintext ciphertext Plaintext
9 14 9

93 Mod 55= 14 1427 Mod 55 = 9

PU= (3, 55) PR= (27, 55)


3. p=7; q=11; e=17; M=8
Answer:
n = p * q = 7 * 11 = 77
f(n) = (p-1) * (q-1) = 6 * 10 = 60
Now, we need to compute d = e-1 mod f(n) by using backward substitution of GCD
algorithm:
According to GCD:
60 = 17 * 3 + 9
17 = 9 * 1 + 8
9=8*1+1
8=1*8+0
Therefore, we have:
1=9–8
= 9 – (17 – 9)
= 9 – (17 – (60 – 17 * 3))
= 60 – 17*3 – (17 – 60 + 17*3)
= 60 – 17 *3 + 60 – 17*4
= 60*2 – 17*7

Hence, we get d = e-1 mod f(n) = e-1 mod 60 = -7 mod 60 = (53-60) mod 60 = 53
So, the public key is {17, 77} and the private key is {53, 77}, RSA encryption and
decryption is following:

Encryption Decryption
Plaintext ciphertext Plaintext
8 57 8

817 Mod 77= 57 5753 Mod 77 = 8

PU= (17, 77) PR= (53, 77)

4. p=11; q=13; e=11; M=7


Answer:
n = p * q = 11 * 13 = 143
f(n) = (p-1) * (q-1) = 10 * 12 = 120
Now, we need to compute d = e-1 mod f(n) by using backward substitution of GCD
algorithm:
According to GCD:
120 = 11 * 10 + 10
11 = 10 * 1 + 1
10 = 1 * 10 + 0
Therefore, we have:
1 = 11 – 10
= 11 – (120 – 11 * 10)
= 11 – 120 + 11 * 10
= -120 + 11 * 11
Hence, we get d = e-1 mod f(n) = e-1 mod 120 = 11 mod 120 = 11
So, the public key is {11, 143} and the private key is {11, 143}, RSA encryption and
decryption is following:

Encryption Decryption
Plaintext ciphertext Plaintext
7 106 7

711 Mod 143 = 10611 Mod 143


106 =8

PU= (11, 143) PR= (11, 143)


5. p=17; q=31; e=7; M=2
n = p * q = 17 * 31 = 527
f(n) = (p-1) * (q-1) = 16 * 30 = 480
Now, we need to compute d = e-1 mod f(n) by using backward substitution of GCD
algorithm:
According to GCD:
480 = 7 * 68 + 4
7=4*1+3
4=3*1+1
3=1*3+0
Therefore, we have:
1=4–3
= 4 – (7 – 4)
= 4 – (7 – (480 – 7*68))
= 4 – (7 – 480 + 7*68)
= 480 – 7*68 – 7 + 480 – 7*68
= 480*2 – 7*137
Hence, we get d = e-1 mod f(n) = e-1 mod 480 = -137 mod 480 = (343 – 480) mod 480
=343
So, the public key is {7, 527} and the private key is {343, 527}, RSA encryption and
decryption is following:

Encryption Decryption
Plaintext ciphertext Plaintext
2 128 2

27 Mod 527 = 128343 Mod 527


128 =2

PU= (7, 527) PR= (343, 527)

Common questions

Powered by AI

Euler's totient function φ(n), calculated as (p-1)(q-1) where p and q are prime numbers, plays a crucial role in RSA encryption by being part of the calculation for the private key exponent 'd'. It ensures that 'e' and 'd' are multiplicative inverses modulo φ(n), facilitating the encryption and decryption processes .

The value of 'd', the private key exponent, is determined using the principle of modular multiplicative inverse. Specifically, it is calculated as 'd = e^-1 mod φ(n)', where 'φ(n)' is Euler's totient function calculated as (p-1)(q-1) for the given prime numbers p and q, and 'e' is the public exponent. The modular multiplicative inverse is typically found using the Extended Euclidean Algorithm, as demonstrated in examples where the steps involve expressing gcd(φ(n), e) in terms of e and φ(n) to isolate d .

For decryption using p=7, q=11, e=17, first calculate n = 77 and φ(n) = 60. Determine d as the modular inverse of e mod φ(n), found using the Extended Euclidean Algorithm to be 53. With public key (17, 77) and private key (53, 77), encrypt M=8 by calculating C = M^e mod n = 8^17 mod 77 = 57. Decrypt using M = C^d mod n = 57^53 mod 77 = 8, confirming proper retrieval of the plaintext. The process showcases correct exponentiation and modular arithmetic compliance, critical in RSA .

The backward substitution method in the RSA algorithm is necessary for determining the precise form of the modular inverse of the public exponent, 'd = e^-1 mod φ(n)'. This method allows for solving the congruences arising from φ(n) and e, ensuring that 'e*d ≡ 1 (mod φ(n))' is satisfied, which is essential for the RSA decryption process to correctly retrieve the plaintext from the ciphertext .

In RSA encryption, the choice of the public exponent 'e' is crucial because it must be coprime with φ(n) and typically an odd prime to ensure a unique integer solution for 'd', essential for the decryption process. The examples show 'e' chosen as small primes (like 3, 7, 11, 17), which are efficient for computation and often lead to simpler calculations for 'd', ensuring the encryption and decryption processes are effective and secure .

The modular inverse in RSA decryption is based on finding an integer 'd' such that 'e*d ≡ 1 (mod φ(n))'. Mathematically, d is the multiplicative inverse of e modulo φ(n), ensuring that when ciphertext is exponentiated by d, it retrieves the original plaintext. This principle uses the Extended Euclidean Algorithm, which enables solving linear Diophantine equations to express 1 as a linear combination of e and φ(n), yielding d .

The GCD algorithm, specifically the Extended Euclidean Algorithm, assists in finding the private key exponent 'd' by calculating the modular inverse of the public exponent 'e' modulo φ(n). This involves using the GCD to express the gcd(e, φ(n)) as a linear combination of e and φ(n), facilitating the derivation of 'd' such that 'e * d ≡ 1 (mod φ(n))' .

Prime numbers are significant in RSA encryption because they ensure the mathematical properties that make it secure. The product of two large primes (n = p*q) is computationally infeasible to factor, which underpins the security of the keys. This reliance on prime factorization safeguards against unauthorized decryption, as the security of RSA hinges on the difficulty of decomposing n back into p and q .

For RSA encryption, take p=3, q=11, e=7, M=5. First, calculate n = p*q = 33 and φ(n) = (p-1)*(q-1) = 20. The private key exponent 'd' is determined using the modular inverse of 'e' mod φ(n), found to be 3. The public key is (e, n) = (7, 33) and the private key is (d, n) = (3, 33). To encrypt a message M=5, compute C = M^e mod n = 5^7 mod 33 = 14. To decrypt, compute M = C^d mod n = 14^3 mod 33 = 5, successfully obtaining the original message .

Security vulnerabilities in RSA related to key size deal mainly with the risk of factorization. Smaller keys, such as 512 bits or less, can be factored relatively quickly with modern computing power, compromising encryption security. Adequate key size is necessary to withstand advances in integer factorization algorithms and increasing computational capabilities. As shown in the sources, even though calculations with smaller n are illustrative, actual security requires larger primes to ensure n remains unfeasible to factor .

You might also like