Cryptography – RSA
IT6010 – Maths for Computing
Objectives:
• Understand the principle of RSA cryptosystem
• Encrypt and decrypt messages using RSA
system
RSA Cryptosystem
• Developed in 1977 by Ron Rivest, Adi
Shamir, and Leonard Adleman
3
RSA Cryptosystem
• one of the first public-key cryptosystems
and is widely used for secure data
transmission.
• It is based on the principle of factoring
large integers, which is computationally
difficult.
• It operates on two main principles in
number theory: prime factorization and
modular arithmetic
• In practice, messages (text, binary, etc.)
are encoded into integer form by using
schemes like ASCII or UTF-8, converting
each character or byte to a numerical
representation. 4
RSA Cryptosystem – ASCII Table
5
Key Components of RSA Cryptography
Public Key (e, n): Used for encrypting
messages and can be shared publicly.
Private Key (d, n): Used for decrypting
messages and must be kept secret.
Here, n = p * q where p and q are large prime
numbers, and e and d are chosen based on
certain properties of n.
6
RSA Cryptography Process
1. Choose two large prime numbers,
p and q, randomly and
independently of each other.
2. Compute n = p * q. The product n
is used as the modulus for both
the public and private keys.
3. Calculate Euler's Totient
Function, φ(n):
(n) = (p-1) * (q-1)
7
RSA Cryptography Process
4. Choose Public Exponent e such
that 1 < e < (n) and
gcd(e, (n)) = 1
5. Compute the Private Exponent
d as the modular multiplicative
inverse of e modulo ϕ(n):
d*e 1 (mod (n))
• Public key: (e, n)
• Private key: (d, n)
8
RSA Cryptography Process
• Commonly Used Values: The most common
value for e is 65537 (216+1) when dealing
with large values (and occasionally 3 or
17).
• Properties of 65537: This number is
specifically chosen because it is a Fermat
prime (of the form 22n+1), which makes it
efficient for modular exponentiation (key
operation in encryption and decryption).
• While values like e = 3 or e = 17 are also
efficient, they are less commonly used
when dealing with large values due to
compatibility concerns and the fact that
they offer less security with some padding
schemes. 9
RSA Encryption and Decryption Formula
𝑬𝒏𝒄𝒓𝒚𝒑𝒕𝒊𝒐𝒏 𝑭𝒖𝒏𝒄𝒕𝒊𝒐𝒏
Using the public key (e, n), the plaintext/message can be
encrypted using,
𝑒
𝐶 =𝑀 𝑚𝑜𝑑 𝑛
𝑫𝒆𝒄𝒓𝒚𝒑𝒕𝒊𝒐𝒏 𝑭𝒖𝒏𝒄𝒕𝒊𝒐𝒏
Using the private key (d, n), the ciphertext can be
decrypted using,
𝑑
𝑀=𝐶 𝑚𝑜𝑑 𝑛 10
Example
Using p = 61 and q = 53, do the following:
1. Compute the public key.
2. Compute the private key.
3. Encrypt the character { in the ASCII table.
4. Decrypt the character in question 3.
Example
Using p = 61 and q = 53, answer the following:
Solution:
1. n = 61 * 53 = 3233
2. (n) = (61-1) * (53-1) = 3120
3. Choose the value of e.(1 < e < 3120)
and gcd(e, 3120) = 1)
Public key:
Possible values of : 7, 11, 13, 17, etc.
(17, 3233)
We can choose e = 17.
Example
Solution:
4. Find d such that 17*d 1 (mod 3120).
Using Extended Euclidean Algorithm,
3120 = 17(183) + 9
9 - 8(1)= 1
17 = 9(1) + 8
17 - 9(1)= 8
9 = 8(1) + 1 3120 - 17(183)= 9
8 = 1(8) + 0
Example
Solution:
4. Find d such that 17*d 1 (mod 3120).
Applying backward substitution,
9 - 8(1)= 1
9 – [17 - 9(1)](1)= 1
9 – 17(1)+9(1)= 1
9(2) – 17(1)= 1
[3120-17(183)](2) – 17(1)= 1
3120(2)-17(366)–17(1)= 1 Private key:
(2753, 3233)
3120(2)-17(367) = 1
d = -367 + 3120 = 2753
Example
Solution:
𝑬𝒏𝒄𝒓𝒚𝒑𝒕𝒊𝒐𝒏 𝑭𝒖𝒏𝒄𝒕𝒊𝒐𝒏 𝑒
𝐶 =𝑀 𝑚𝑜𝑑 𝑛
17
Encrypt the character {.
𝐶 =𝑀 𝑚𝑜𝑑 32
{ in the ASCII
17
123 𝑚𝑜𝑑 3233=( 2136 ∗ 123 ) 𝑚𝑜𝑑 3233= 855
Example
Solution:
𝑑
Decryption 𝑀=𝐶 𝑚𝑜𝑑 𝑛
2753
Decrypt the character 855.
𝑀=𝐶 𝑚𝑜𝑑 32
Example
Solution:
𝑑
Decryption 𝑀=𝐶 𝑚𝑜𝑑 𝑛
2753
Decrypt the character 855. 𝑀=𝐶 𝑚𝑜𝑑 323
2048
855 𝑚𝑜𝑑 3233=( 2197 ∗ 1160 ∗1709 ∗ 916 ∗ 855 ) 𝑚𝑜𝑑 32
𝑀=123={
Let’s try this!
1. Encrypt the character J in the ASCII table using p = 43
and q = 59.
2. What is the original character in the ASCII table
encrypted using p = 61 and q = 47 if the encrypted
character is 1112?