Implementing RSA algorithm, Assignments of Computer science

this is my assignment on how to implement RSA algorithm

Typology: Assignments

2020/2021

Uploaded on 11/26/2021

rizwan-shaikh-3
rizwan-shaikh-3 🇮🇳

1 document

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Experiment 4
Aim: - Implementing RSA Algorithm
Theory: - The RSA algorithm is named after those who invented it in 1978: Ron
Rivest, Adi Shamir, and Leonard Adleman.
The RSA algorithm is an asymmetric cryptography algorithm; this means that it
uses a public key and a private key (i.e two different, mathematically linked keys).
As their names suggest, a public key is shared publicly, while a private key is
secret and must not be shared with anyone.
How it works:
The RSA algorithm ensures that the keys, in the above illustration, are as secure
as possible. The following steps highlight how it works:
1. Generating the keys
i. Select two large prime numbers, xx and yy. The prime numbers need to be
large so that they will be difficult for someone to figure out.
ii. Calculate n = xn=x x yy.
iii. Calculate the totient function; \phi(n) = (x-1)(y-1)ϕ(n)=(x−1)(y−1).
iv. Select an integer ee, such that ee is co-prime to \phi(n)ϕ(n) and 1 < e < \
phi(n)1<e<ϕ(n). The pair of numbers (n,e)(n,e) makes up the public key.
v. Calculate dd such that e.d = 1e.d=1 modmod \phi(n)ϕ(n).
d can be found using the extended euclidean algorithm. The pair (n,d)(n,d) makes
up the private key.
2. Encryption
Given a plaintext PP, represented as a number, the ciphertext CC is calculated as:
pf3
pf4

Partial preview of the text

Download Implementing RSA algorithm and more Assignments Computer science in PDF only on Docsity!

Experiment 4

Aim: - Implementing RSA Algorithm

Theory: - The RSA algorithm is named after those who invented it in 1978: Ron

Rivest, Adi Shamir, and Leonard Adleman.

The RSA algorithm is an asymmetric cryptography algorithm; this means that it

uses a public key and a private key (i.e two different, mathematically linked keys).

As their names suggest, a public key is shared publicly, while a private key is

secret and must not be shared with anyone.

How it works:

The RSA algorithm ensures that the keys, in the above illustration, are as secure

as possible. The following steps highlight how it works:

1. Generating the keys

i. Select two large prime numbers, x x and y y. The prime numbers need to be

large so that they will be difficult for someone to figure out.

ii. Calculate n = x n = x x y y.

iii. Calculate the totient function; \phi(n) = (x-1)(y-1) ϕ ( n )=( x −1)( y −1).

iv. Select an integer e e , such that e e is co-prime to \phi(n) ϕ ( n ) and 1 < e < \

phi(n)1< e < ϕ ( n ). The pair of numbers (n,e)( n , e ) makes up the public key.

v. Calculate d d such that e.d = 1 e. d =1 mod mod \phi(n) ϕ ( n ).

d can be found using the extended euclidean algorithm. The pair (n,d)( n , d ) makes

up the private key.

2. Encryption

Given a plaintext P P , represented as a number, the ciphertext C C is calculated as:

C = P^{e} C = Pe mod mod n n.

3. Decryption

Using the private key (n,d)( n , d ), the plaintext can be found using:

P = C^{d} P = Cd mod mod n n.

Implementation: -

// C program for RSA asymmetric cryptographic // algorithm. For demonstration values are // relatively small compared to practical // application #include<stdio.h> #include<math.h> // Returns gcd of a and b int gcd( int a, int h) { int temp; while (1) { temp = a%h; if (temp == 0) return h; a = h; h = temp; } } // Code to demonstrate RSA algorithm int main() { // Two random prime numbers double p = 3; double q = 7; // First part of public key: double n = p*q;

Original Message Sent = 12.

Conclusion:

Advantages of RSA algorithm:

 RSA algorithm is safe and secure for its users through the use of complex

mathematics.

 RSA algorithm is hard to crack since it involves factorization of prime

numbers which are difficult to factorize.

 RSA algorithm uses the public key to encrypt data and the key is known to

everyone, therefore, it is easy to share the public key

Disadvantages of RSA algorithm:

 RSA algorithm can be very slow in cases where large data needs to be

encrypted by the same computer.

 It requires a third party to verify the reliability of public keys.

 Data transferred through RSA algorithm could be compromised through

middlemen who might temper with the public key system.

In conclusion , both the symmetric encryption technique and the asymmetric

encryption technique are important in encryption of sensitive data