Exp7 RSA 041
Exp7 RSA 041
Date of
26/03/2025 DIV/ Batch No: C3
Performance:
Experiment No:7
Title: Implementation of RSA algorithm
COs to be achieved:
CO2: Demonstrate and implement various Cryptographic Algorithms for securing systems.
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.
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
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.
RSA Algorithm is based on factorization of large number and modular arithmetic for encrypting
and decrypting data. It consists of three main stages:
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
● 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.
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).
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:
import math
while b:
a, b = b, a % b
return a
result = 1
if exp % 2 == 1:
exp //= 2
return result
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
p, q = 61, 53
n = p * q
phi = (p - 1) * (q - 1)
e = 17
e += 1
d = mod_inverse(e, phi)
cipher_text = mod_expo(message, e, n)
decrypted_message = mod_expo(cipher_text, d, n)
OUTPUT:
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.
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: