0% found this document useful (0 votes)
2 views10 pages

Exp7 RSA 041

The document outlines an experiment on the implementation of the RSA algorithm as part of the Applied Cryptography course at K. J. Somaiya School of Engineering. It explains the principles of asymmetric key cryptography, details the RSA algorithm's key generation, encryption, and decryption processes, and includes code for practical application. Additionally, it discusses the strengths and weaknesses of RSA, its applications in secure communications, and concludes with the successful study and implementation of the algorithm.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views10 pages

Exp7 RSA 041

The document outlines an experiment on the implementation of the RSA algorithm as part of the Applied Cryptography course at K. J. Somaiya School of Engineering. It explains the principles of asymmetric key cryptography, details the RSA algorithm's key generation, encryption, and decryption processes, and includes code for practical application. Additionally, it discusses the strengths and weaknesses of RSA, its applications in secure communications, and concludes with the successful study and implementation of the algorithm.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

K. J.

Somaiya School of Engineering, Mumbai-77

(Somaiya Vidyavihar University)

Department of Computer Engineering

Course Name: Applied Cryptography 116U01E628 Semester: VI

Date of
26/03/2025 DIV/ Batch No: C3
Performance:

Student Name: Rohit Deshpande Roll No: 16010122041

Experiment No:7
Title: Implementation of RSA algorithm

Aim and Objective of the Experiment:

Implementation of RSA algorithm

COs to be achieved:

CO2: Demonstrate and implement various Cryptographic Algorithms for securing systems.

Books/ Journals/ Websites referred:

1. Stallings, W., Cryptography and Network Security: Principles and Practice, Second edition, Person
Education
2. Forouzan, B. A. (2018). Cryptography and Network Security. McGraw-Hill Education.

Theory: Explain the following.

Asymmetric key cryptography is essential for secure communication over untrusted networks,
solving key distribution and authentication challenges present in symmetric encryption. In
traditional symmetric encryption, both sender and receiver must share a single secret key, which
poses a risk if intercepted during transmission. Asymmetric cryptography eliminates this risk by
employing a public-private key pair, ensuring that encryption and decryption keys are distinct.

The public key is openly shared and used for encrypting messages, while only the recipient
possessing the private key can decrypt them. This approach guarantees confidentiality, as

Applied Cryptography Semester: VI Academic Year: 2024-25


K. J. Somaiya School of Engineering, Mumbai-77

(Somaiya Vidyavihar University)

Department of Computer Engineering

unauthorized parties cannot access the plaintext message. Additionally, asymmetric cryptography
enhances authentication through digital signatures, where a sender signs a message with their
private key, and the recipient verifies its authenticity using the sender’s public key.

This cryptographic method is crucial for securing online transactions, digital certificates, secure
email communication (PGP, S/MIME), and access control mechanisms. It is also the
foundation of zero-trust security models, where authentication occurs at every stage, rather than
relying on a trusted internal network. Asymmetric encryption is fundamental to public key
infrastructure (PKI), used in SSL/TLS protocols for encrypting web traffic, preventing man-in-
the-middle attacks, and ensuring secure browsing.

Although asymmetric encryption provides strong security, it is computationally slower than


symmetric encryption, making it impractical for encrypting large amounts of data. In real-world
applications, hybrid cryptographic approaches combine asymmetric encryption for key exchange
and symmetric encryption for bulk data encryption, optimizing both security and efficiency.

RSA(Rivest-Shamir-Adleman) Algorithm is an asymmetric or public-key cryptography algorithm


which means it works on two different keys: Public Key and Private Key. The Public Key is used
for encryption and is known to everyone, while the Private Key is used for decryption and must be
kept secret by the receiver. RSA Algorithm is named after Ron Rivest, Adi Shamir and Leonard
Adleman, who published the algorithm in 1977.

RSA Algorithm is based on factorization of large number and modular arithmetic for encrypting
and decrypting data. It consists of three main stages:

1. Key Generation: Creating Public and Private Keys

2. Encryption: Sender encrypts the data using Public Key to get cipher text.

3. Decryption: Decrypting the cipher text using Private Key to get the original data.

1. Key Generation

Applied Cryptography Semester: VI Academic Year: 2024-25


K. J. Somaiya School of Engineering, Mumbai-77

(Somaiya Vidyavihar University)

Department of Computer Engineering

● Choose two large prime numbers, say p and q. These prime numbers should be kept
secret.

● Calculate the product of primes, n = p * q. This product is part of the public as well as
the private key.

● Calculate Euler’s Totien Function


Φ(n) as Φ(n) = Φ(p * q) = Φ(p) * Φ(q) = (p – 1) * (q – 1).

● Choose encryption exponent e, such that

○ 1 < e < Φ(n), and

○ gcd(e, Φ(n)) = 1, that is e should be co-prime with Φ(n).

● Calculate decryption exponent d, such that

(d * e) 1 mod (n), d is modular multiplicative inverse of e mod (n). Some common m

We can have multiple values of d satisfying (d * e) 1 mod (n) but it does not matter w

○ Finally, the Public Key = (n, e) and the Private Key = (n, d).

2. Encryption: To encrypt a message M, it is first converted to numerical representation using

Applied Cryptography Semester: VI Academic Year: 2024-25


K. J. Somaiya School of Engineering, Mumbai-77

(Somaiya Vidyavihar University)

Department of Computer Engineering

ASCII and other encoding schemes. Now, use the public key (n, e) to encrypt the message and get
the cipher text using the formula:

C = Me mod n, where C is the Cipher text and e and n are parts of public key.

3. Decryption

To decrypt the cipher text C, use the private key (n, d) and get the original data using the formula:

M = Cd mod n, where M is the message and d and n are parts of private key.

Code and Output :

CODE:

Applied Cryptography Semester: VI Academic Year: 2024-25


K. J. Somaiya School of Engineering, Mumbai-77

(Somaiya Vidyavihar University)

Department of Computer Engineering

import math

def gcd(a, b):

while b:

a, b = b, a % b

return a

def mod_expo(base, exp, mod):

result = 1

while exp > 0:

if exp % 2 == 1:

result = (result * base) % mod

base = (base * base) % mod

exp //= 2

return result

def mod_inverse(e, phi):

d, x1, x2, y1 = 0, 0, 1, 1

temp_phi = phi

while e > 0:

q = temp_phi // e

e, temp_phi = temp_phi % e, e

x1, x2 = x2 - q * x1, x1

y1, d = d - q * y1, y1

Applied Cryptography Semester: VI Academic Year: 2024-25


K. J. Somaiya School of Engineering, Mumbai-77

(Somaiya Vidyavihar University)

Department of Computer Engineering

return d + phi if d < 0 else d

p, q = 61, 53

n = p * q

phi = (p - 1) * (q - 1)

e = 17

while gcd(e, phi) != 1:

e += 1

d = mod_inverse(e, phi)

print(f"Public Key: ({n}, {e})")

message = int(input("\nEnter a message (as an integer): "))

cipher_text = mod_expo(message, e, n)

print(f"Encrypted message (Cipher Text): {cipher_text}")

decrypted_message = mod_expo(cipher_text, d, n)

print(f"Decrypted message: {decrypted_message}")

Applied Cryptography Semester: VI Academic Year: 2024-25


K. J. Somaiya School of Engineering, Mumbai-77

(Somaiya Vidyavihar University)

Department of Computer Engineering

OUTPUT:

Post Lab Subjective/Objective type Questions:

Applied Cryptography Semester: VI Academic Year: 2024-25


K. J. Somaiya School of Engineering, Mumbai-77

(Somaiya Vidyavihar University)

Department of Computer Engineering

1. Solve one example using RSA algorithm.

Applied Cryptography Semester: VI Academic Year: 2024-25


K. J. Somaiya School of Engineering, Mumbai-77

(Somaiya Vidyavihar University)

Department of Computer Engineering

2. Write Applications of RSA.

RSA is widely used in various domains that require secure data transmission and authentication. It
is a fundamental component of HTTPS encryption, ensuring safe browsing by securing
communications between web browsers and servers. Email security protocols, such as PGP (Pretty
Good Privacy) and S/MIME, use RSA for encrypting messages and verifying digital signatures. In
online banking and e-commerce, RSA secures transactions and prevents unauthorized access. It is
also extensively used in digital signatures, ensuring data integrity and authenticity in legal and
financial documents. Blockchain technology employs RSA for secure transactions and
authentication mechanisms. Furthermore, Virtual Private Networks (VPNs) use RSA to establish
encrypted communication channels, safeguarding sensitive user data from cyber threats.

3. Comment on the strengths and weaknesses of RSA.

RSA is one of the most widely used public-key cryptosystems due to its strong security foundation
based on the difficulty of factoring large prime numbers. It provides highly secure encryption and
authentication, making it ideal for protecting sensitive information in communications and digital
transactions. Additionally, it enables non-repudiation through digital signatures, ensuring message
authenticity. However, RSA has certain drawbacks. It is computationally slower compared to
symmetric encryption algorithms like AES, making it inefficient for encrypting large volumes of
data. Key generation and encryption/decryption processes require significant computational
power, which can be a bottleneck for resource-limited devices. Furthermore, RSA is vulnerable to
quantum computing advancements, as quantum algorithms like Shor’s algorithm could potentially
break RSA encryption by efficiently factoring large numbers.

Conclusion:

Applied Cryptography Semester: VI Academic Year: 2024-25


K. J. Somaiya School of Engineering, Mumbai-77

(Somaiya Vidyavihar University)

Department of Computer Engineering

Hence, RSA algorithm was studied, understood and implemented.

Applied Cryptography Semester: VI Academic Year: 2024-25

You might also like