Table of Contents

ToggleHello everyone ðŸ™‚ Lucifer is here to explain to you guys what is RSA algorithm and how it works. Today in this article we are going to understand the working of the RSA algorithm with some examples that what is going over there.

After reading this article you’ll be able to know the working of RSA and be able to do mathematical calculations of the RSA algorithm. RSA is a Block cipher.

RSA (Rivest, Shamir, Adleman) algorithm was first described in 1977. It is an asymmetric cryptography algorithm with private and public keys in it. The public key is used for encryption and the private key is used for decryption.

## Steps to calculate RSA

### 1. Key Generation

- Select two prime numbers p and q respectively
- Calculate n=p*q
- calculate Î¦(n)=(p-1)*(q-1)
- Euler’s Totient Function

- Exponential GCD [Î¦(n), e] = 1
- Condition = 1<e<Î¦(n)
- GCD = Greatest Common Division

- Calculate [de mod Î¦(n) = 1]
- Public key = [e, n]
- Private key = [d, n]

### 2. Encryption

- c = m
^{e }mod n- [m = plaintext]
- [m < n]
- [c = ciphertext]
- [m will be no. of words in your message]

### 3. Decryption

- m = c
^{d }mod n

## Example -1 RSA algorithm

```
Let's understand with an example
Assume p = 3, q = 11
n = 3x11 = 33 [i.e. n = pxq]
Î¦(n) = 2x10 = 20 [i.e Î¦(n) = (p-1)(q-1)]
So, let's take
e = 7 [1<7<20 and gcd ((7,20) = 1) ]
Now,
de mod Î¦(n) = 1
7xd mod Î¦(n) = 1
7xd mod 20 = 1
```^{[ *}*^{*} d = 3]
**Since e = 7, d = 3**
Public key = [e, n] = [7, 33]
Private key = [d, n] = [3, 33]
Let's take message = 31
**Encryption**
c = m^{e} mod n
c = 31^{7 }mod 33
c = 27512614111 mod 33
**c = 4**
**Decryption**
m = c^{d} mod n
m = 4^{3} mod 33
m = 64 mod 33
**m = 31**

**Note:-**

[e, n] is a public key used in encryption, and [d, n] is a private key used for decryption.

## Example – 2 RSA algorithm

```
Let's see another example
Assume p = 61, q = 53
n = 61x53 = 3233 [i.e. n = pxq]
Î¦(n) = 60x52 = 3120 [i.e Î¦(n) = (p-1)(q-1)]
So, let's take
e = 17 [1<17<3120 and gcd ((17, 3120) = 1) ]
Now,
de mod Î¦(n) = 1
17xd mod Î¦(n) = 1
17xd mod 3120 = 1
```^{[ *}*^{*} d = 2753]
**Since e = 17, d = 2753**
Public key = [e, n] = [17, 3233]
Private key = [d, n] = [2753, 3233]
Let's take message = 123
**Encryption**
c = m^{e} mod n
c = 123^{17 }mod 3233
**c = 855**
**Decryption**
m = c^{d} mod n
m = 855^{2753} mod 3233
**m = 123**

## Usage of the RSA algorithm

- This uses in banks for securing customer data and transaction details
- It uses in telecommunication for encrypting call data
- Uses in e-commerce for securing users’ identity for transactions

**If you have any queries regarding the above content, or you want to update anything in the content, thenÂ contact usÂ with your queries. You can directly post your question in theÂ group.**

**Connect with us on these platforms**