0% found this document useful (0 votes)
27 views22 pages

NIS MicroProject ISHA

The document outlines a micro project on the implementation of RSA encryption, submitted for a Diploma in Engineering in Artificial Intelligence & Machine Learning. It details the RSA algorithm's key generation, encryption, and decryption processes, along with an action plan, required resources, and implementation in multiple programming languages. The project aims to demonstrate secure data transmission using asymmetric cryptography principles.

Uploaded by

Anonymous om
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views22 pages

NIS MicroProject ISHA

The document outlines a micro project on the implementation of RSA encryption, submitted for a Diploma in Engineering in Artificial Intelligence & Machine Learning. It details the RSA algorithm's key generation, encryption, and decryption processes, along with an action plan, required resources, and implementation in multiple programming languages. The project aims to demonstrate secure data transmission using asymmetric cryptography principles.

Uploaded by

Anonymous om
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

A

Micro Project
on
“Implementation of RSA Encryption”
Submitted in partial fulfillment of the requirement for the award of
Diploma of Engineering
in
Artificial Intelligence & Machine Learning
By

Nishita Rao

under the guidance of

Pratik Gurav

Department of Artificial Intelligence


2024 - 25
CERTIFICATE

VIVA COLLEGE OF DIPLOMA ENGINEERING & TECHNOLOGY


VIRAR (W)
2024 - 25

This is to certify that the micro project entitled “Implementation of RSA Encryption
” has been submitted under the guidance of Mr.Pratik Gurav in partial fulfillment of
the requirement for the award of a Diploma of Engineering in Artificial Intelligence
& Machine Learning from the Maharashtra State Board of Technical Education.

“Implementation of Columnar Transposition Cipher”


GROUP MEMBERS
27-Nishita Rao

Project Guide H.O.D


Prof. Pratik Gurav Prof. Poonam Jadhav
INDEX

Sr. No. Name of the topic Page no.

PART – A PLAN

1 Brief Introduction 1

2 Aim of the Micro-Project 2

3 Action Plan 3

4 Resources Required 4

PART –B OUTCOMES

1 Brief Description 5

2 Aim of Micro-Project 14

3 Course Outcomes Integrated 15

4 Actual Procedure Followed 16

5 Actual Resources Used 17

6 Outputs of the Micro-Projects 19

7 Skill Developed/ learning out of this Micro-Project 19


RSA ENCRYPTION NIS 22620, Sem VI

PART-A
1.0 Brief Introduction

RSA (Rivest-Shamir-Adleman) is a widely used asymmetric encryption algorithm that ensures secure
data transmission by using a public key for encryption and a private key for decryption. It is based on
the mathematical difficulty of factoring large prime numbers, making it highly secure for digital
communications.
The RSA algorithm follows three main steps:
1. Key Generation – Two large prime numbers (ppp and qqq) are chosen, and their product (n=p×qn
= p \times qn=p×q) is used as a modulus. A public exponent (eee) is selected, and a private
exponent (ddd) is computed to satisfy modular arithmetic properties.
2. Encryption – The sender converts the message into a numerical format and applies the formula
C=Memod nC = M^e \mod nC=Memodn, where CCC is the ciphertext.
3. Decryption – The receiver, using the private key (ddd), recovers the original message using
M=Cdmod nM = C^d \mod nM=Cdmodn.
RSA is commonly used in secure communications, digital signatures, and authentication protocols.
Although it is computationally expensive, its security relies on the challenge of prime factorization.
Modern implementations optimize RSA by using hybrid encryption, where RSA encrypts a symmetric
key for faster data transmission.

VIVA COLLEGE OF DIPLOMA ENGG & TECH, Artificial Intelligence & Machine Learning . 1
RSA ENCRYPTION NIS 22620, Sem VI

2.0 AIM of Micro-Project

The aim of this project is to implement a simplified RSA encryption system for secure data
transmission. This project demonstrates the principles of asymmetric cryptography, where a public
key encrypts data and a private key decrypts it, ensuring confidentiality and authentication in digital
communication.

VIVA COLLEGE OF DIPLOMA ENGG & TECH, Artificial Intelligence & Machine Learning . 2
RSA ENCRYPTION NIS 22620, Sem VI

3.0 Action Plan

Sr. Details of Activity Planned Planned Name of Responsible


No Start Finish Team Members
Date Date

1 Project selection 2/1/25 16/1/25

2 Identifying project 16/1/25 23/1/25


outcomes

3 Identifying 23/1/25 6/2/25


resources required

4 Implementation of Project 6/2/25 06/3/25

5 Final outcome 06/3/25 20/3/25

6 Documentation 20/3/25 03/4/25 .

VIVA COLLEGE OF DIPLOMA ENGG & TECH, Artificial Intelligence & Machine Learning . 3
RSA ENCRYPTION NIS 22620, Sem VI

3.0 Resources Required

Sr. Name of Specification Qty Remarks


No Resource
512GB SSD,
1 Computer 8 Gb RAM, 1
AMD
processor,
Windows 10
OS

VIVA COLLEGE OF DIPLOMA ENGG & TECH, Artificial Intelligence & Machine Learning . 4
RSA ENCRYPTION NIS 22620, Sem VI

PART-B OUTCOME

1.0 Brief Description

• Implementation of Columnar Transposition Cipher:


Implementation of RSA Encryption
The RSA encryption system is implemented in three main steps:
1. Key Generation:
o Select two large prime numbers (ppp and qqq) and compute their product n=p×qn = p
\times qn=p×q.
o Calculate Euler’s totient function ϕ(n)=(p−1)×(q−1)\phi(n) = (p-1) \times (q-
1)ϕ(n)=(p−1)×(q−1).
o Choose a public exponent eee (commonly 65537) and compute the private key ddd such
that (e×d)mod ϕ(n)=1(e \times d) \mod \phi(n) = 1(e×d)modϕ(n)=1.
2. Encryption:
o Convert the plaintext message into a numerical format.
o Compute ciphertext using the formula: C=Memod nC = M^e \mod nC=Memodn.
3. Decryption:
o Recover the original message using: M=Cdmod nM = C^d \mod nM=Cdmodn
.

• Key Features of RSA Encryption Project:

1. Asymmetric Encryption – Uses a public key for encryption and a private key for decryption,
ensuring secure communication.

2. Key Generation – Randomly generates two prime numbers, computes public and private keys
dynamically.

3. Strong Security – Based on the mathematical difficulty of prime factorization, making


decr8yption without the private key nearly impossible.

4. Encryption & Decryption – Converts text into numeric form, applies modular exponentiation,
and retrieves the original message securely

VIVA COLLEGE OF DIPLOMA ENGG & TECH, Artificial Intelligence & Machine Learning . 5
RSA ENCRYPTION NIS 22620, Sem VI

• IMPLEMENTATION IN PYTHON:-
import random
# Function to compute Greatest Common Divisor (GCD)
def gcd(a, b):
while b:
a, b = b, a % b
return a
# Function to compute Modular Inverse (d) using Extended Euclidean Algorithm
def mod_inverse(e, phi):
for d in range(2, phi):
if (e * d) % phi == 1:
return d
return None
# Function to check if a number is prime
def is_prime(n):
if n < 2:
return False
for i in range(2, int(n ** 0.5) + 1):
if n % i == 0:
return False
return True
# Function to generate a random prime number
def generate_prime():
while True:
num = random.randint(50, 200) # Choose a random number in a given range
if is_prime(num):
return num
# Function to generate RSA Public and Private Keys
def generate_keys():
p, q = generate_prime(), generate_prime()
while p == q: # Ensure p and q are distinct
q = generate_prime()

VIVA COLLEGE OF DIPLOMA ENGG & TECH, Artificial Intelligence & Machine Learning . 6
RSA ENCRYPTION NIS 22620, Sem VI

n=p*q
phi = (p - 1) * (q - 1)
# Choose e such that 1 < e < phi(n) and GCD(e, phi) = 1
e = random.randint(2, phi - 1)
while gcd(e, phi) != 1:
e = random.randint(2, phi - 1)
# Compute d (private key) using modular inverse
d = mod_inverse(e, phi)

return ((e, n), (d, n)) # Public and Private keys


# Function for RSA Encryption
def encrypt(plaintext, public_key):
e, n = public_key
encrypted_text = [pow(ord(char), e, n) for char in plaintext]
return encrypted_text

# Function for RSA Decryption


def decrypt(ciphertext, private_key):
d, n = private_key
decrypted_text = ''.join([chr(pow(char, d, n)) for char in ciphertext])
return decrypted_text

# Main Program
public_key, private_key = generate_keys()

message = "HELLO"
ciphertext = encrypt(message, public_key)
decrypted_message = decrypt(ciphertext, private_key)
print(f"Original Message: {message}")
print(f"Encrypted Message: {ciphertext}")
print(f"Decrypted Message: {decrypted_message}")

VIVA COLLEGE OF DIPLOMA ENGG & TECH, Artificial Intelligence & Machine Learning . 7
RSA ENCRYPTION NIS 22620, Sem VI

• IMPLEMENTATION IN C:-
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
// Function to compute GCD (Greatest Common Divisor)
int gcd(int a, int b) {
while (b != 0) {
int temp = b;
b = a % b;
a = temp;
}
return a;
}
// Function to find modular inverse using Extended Euclidean Algorithm
int modInverse(int e, int phi) {
for (int d = 2; d < phi; d++) {
if ((e * d) % phi == 1) {
return d;
}
}
return -1;
}

// Function to check if a number is prime


int isPrime(int num) {
if (num < 2) return 0;
for (int i = 2; i <= sqrt(num); i++) {
if (num % i == 0) return 0;
}
return 1;
}
// Function to generate a prime number within a range
int generatePrime() {
int num;
while (1) {
num = rand() % 50 + 10; // Generate number between 10 and 60
if (isPrime(num)) return num;
}
VIVA COLLEGE OF DIPLOMA ENGG & TECH, Artificial Intelligence & Machine Learning . 8
RSA ENCRYPTION NIS 22620, Sem VI

}
// RSA Key Generation
void generateKeys(int *e, int *d, int *n) {
int p = generatePrime();
int q = generatePrime();
while (p == q) { // Ensure p and q are different
q = generatePrime();
}

*n = p * q;
int phi = (p - 1) * (q - 1);

*e = 2;
while (*e < phi && gcd(*e, phi) != 1) {
(*e)++;
}

*d = modInverse(*e, phi);
}

// RSA Encryption
int encrypt(int msg, int e, int n) {
int cipher = 1;
for (int i = 0; i < e; i++) {
cipher = (cipher * msg) % n;
}
return cipher;
}

// RSA Decryption
int decrypt(int cipher, int d, int n) {
int msg = 1;
for (int i = 0; i < d; i++) {
msg = (msg * cipher) % n;
}
return msg;
}

VIVA COLLEGE OF DIPLOMA ENGG & TECH, Artificial Intelligence & Machine Learning . 9
RSA ENCRYPTION NIS 22620, Sem VI

int main() {
int e, d, n;
generateKeys(&e, &d, &n);

printf("Public Key: (e = %d, n = %d)\n", e, n);


printf("Private Key: (d = %d, n = %d)\n", d, n);

int msg;
printf("Enter a number to encrypt (numeric message): ");
scanf("%d", &msg);

int cipher = encrypt(msg, e, n);


printf("Encrypted Message: %d\n", cipher);

int decrypted_msg = decrypt(cipher, d, n);


printf("Decrypted Message: %d\n", decrypted_msg);

return 0;
}

IMPLEMENTATION IN JAVA:
import java.math.BigInteger;
import java.security.SecureRandom;
import java.util.Scanner;

public class RSA {


private BigInteger p, q, n, phi, e, d;
private int bitLength = 1024;
private SecureRandom random;

// Constructor to generate keys


public RSA() {
random = new SecureRandom();
p = BigInteger.probablePrime(bitLength / 2, random);
q = BigInteger.probablePrime(bitLength / 2, random);
n = p.multiply(q);
phi = (p.subtract(BigInteger.ONE)).multiply(q.subtract(BigInteger.ONE));

VIVA COLLEGE OF DIPLOMA ENGG & TECH, Artificial Intelligence & Machine Learning . 10
RSA ENCRYPTION NIS 22620, Sem VI

e = BigInteger.probablePrime(bitLength / 2, random);
while (phi.gcd(e).intValue() > 1) {
e = BigInteger.probablePrime(bitLength / 2, random);
}

d = e.modInverse(phi);
}

// Encrypt method
public BigInteger encrypt(BigInteger message) {
return message.modPow(e, n);
}

// Decrypt method
public BigInteger decrypt(BigInteger encrypted) {
return encrypted.modPow(d, n);
}

// Get Public Key


public BigInteger getPublicKey() {
return e;
}

// Get Private Key


public BigInteger getPrivateKey() {
return d;
}

// Get Modulus
public BigInteger getModulus() {
return n;
}

public static void main(String[] args) {


RSA rsa = new RSA();
Scanner scanner = new Scanner(System.in);

// Display generated keys


VIVA COLLEGE OF DIPLOMA ENGG & TECH, Artificial Intelligence & Machine Learning . 11
RSA ENCRYPTION NIS 22620, Sem VI

System.out.println("Public Key: (e = " + rsa.getPublicKey() + ", n = " + rsa.getModulus() + ")");


System.out.println("Private Key: (d = " + rsa.getPrivateKey() + ", n = " + rsa.getModulus() + ")");

// Get user input for encryption


System.out.print("Enter a numeric message to encrypt: ");
BigInteger message = scanner.nextBigInteger();

// Encrypt the message


BigInteger encrypted = rsa.encrypt(message);
System.out.println("Encrypted Message: " + encrypted);

// Decrypt the message


BigInteger decrypted = rsa.decrypt(encrypted);
System.out.println("Decrypted Message: " + decrypted);

scanner.close();
}

• Advantages of the Modified Caesar Cipher:

1. Strong Security
• Based on the difficulty of prime factorization, making it nearly impossible to break with brute
force attacks.
2. Public-Key Cryptography
• Uses asymmetric encryption, where the public key encrypts data and the private key decrypts it,
ensuring secure communication.
3. Digital Signatures
• Supports authentication and integrity verification, making it useful for digital signatures and
certificates.
4. Secure Data Transmission
• Used in secure email, online transactions, VPNs, and SSL/TLS to protect sensitive information

VIVA COLLEGE OF DIPLOMA ENGG & TECH, Artificial Intelligence & Machine Learning . 12
RSA ENCRYPTION NIS 22620, Sem VI

2.0AIM of Micro-Project

The aim of this project is to implement and demonstrate RSA encryption and decryption using
asymmetric cryptography. This includes:
• Generating secure public and private keys for encryption and decryption.
• Encrypting sensitive data using the public key to ensure confidentiality.
• Decrypting the encrypted data using the private key for secure communication.
• Ensuring data integrity and authentication using RSA principles.
• Providing a practical understanding of cryptographic security and its applications in secure
messaging, digital signatures, and secure transactions.
.

VIVA COLLEGE OF DIPLOMA ENGG & TECH, Artificial Intelligence & Machine Learning . 13
RSA ENCRYPTION NIS 22620, Sem VI

3.0 Course Outcomes (CO)

1. Understand Cryptographic Principles


2. Implement RSA Algorithm
3. Apply Modular Arithmetic
4. Enhance Security Awareness
5. Develop Problem-Solving Skills

VIVA COLLEGE OF DIPLOMA ENGG & TECH, Artificial Intelligence & Machine Learning . 14
RSA ENCRYPTION NIS 22620, Sem VI

4.0 Procedure Followed

Procedure Followed in Implementing RSA Encryption

Step 1: Key Generation

1. Select Two Prime Numbers – Choose two large prime numbers p and q.

2. Compute Modulus (n) – Calculate n = p × q.

3. Calculate Euler’s Totient Function (φ(n)) – Compute φ(n) = (p - 1) × (q - 1).

4. Choose Public Key (e) – Select e such that 1 < e < φ(n) and gcd(e, φ(n)) = 1 (e and φ(n) are
coprime).

5. Compute Private Key (d) – Find d such that (e × d) % φ(n) = 1 (modular inverse of e).

Step 2: Encryption

1. Convert the message (M) into numeric form (if it’s text, convert characters to ASCII
values).

2. Apply RSA Encryption Formula:

o C = M^e mod n

o C is the encrypted message (ciphertext).

Step 3: Decryption

1. Apply RSA Decryption Formula:

o M = C^d mod n

o Retrieves the original message.

VIVA COLLEGE OF DIPLOMA ENGG & TECH, Artificial Intelligence & Machine Learning . 15
RSA ENCRYPTION NIS 22620, Sem VI

Step 4: Testing & Validation

1. Encrypt a sample message using the public key.

2. Decrypt the ciphertext using the private key.

3. Verify that the decrypted message matches the original input.

VIVA COLLEGE OF DIPLOMA ENGG & TECH, Artificial Intelligence & Machine Learning . 16
RSA ENCRYPTION NIS 22620, Sem VI

5.0 Resources Used

Sr. Name of Specification Qty Remarks


No Resource
1TB HDD,
1 Computer 8 GB RAM, 1
Intel
processor,
Windows 10
OS

VIVA COLLEGE OF DIPLOMA ENGG & TECH, Artificial Intelligence & Machine Learning . 17
RSA ENCRYPTION NIS 22620, Sem VI

6.0 Outputs of Micro-Projects

Basic Numeric RSA Encryption & Decryption


• The system generates a public and private key pair.
• The user enters a numeric message to encrypt.
• The program encrypts the message using the public key and displays the encrypted result.
• The encrypted message is then decrypted using the private key, and the original message is
retrieved and displayed.

RSA Encryption with String Messages


• The system generates the RSA key pair.
• The user enters a text message (e.g., "HELLO").
• The message is converted into numeric form, then encrypted using the public key.
• The encrypted values are displayed as a sequence of numbers.
• The program decrypts the message using the private key and displays the original text.

Digital Signature Verification Using RSA


• A message is signed using the private key to generate a digital signature.
• The signature is verified using the public key.
• If valid, the system confirms that the message was not altered and was sent by the correct
sender.
• If invalid, the system warns that the message may have been tampered with or sent by an
unauthorized source.

RSA Key Pair Generation


• The system generates a random public and private key pair based on large prime numbers.
• The keys are displayed so they can be used for encryption and decryption.

VIVA COLLEGE OF DIPLOMA ENGG & TECH, Artificial Intelligence & Machine Learning . 18
RSA ENCRYPTION NIS 22620, Sem VI

7.0 Skills Developed/Learning Out of this Micro-Project

1. Understanding Cryptography – Learn RSA encryption, key generation, and decryption.


2. Programming Skills – Implement RSA in Java, C, or Python.
3. Mathematical Knowledge – Apply modular arithmetic and prime number selection.
4. Cybersecurity Awareness – Understand data security and encryption in real-world
applications.
5. Problem-Solving Ability – Debug and optimize encryption algorithms.

Conclusion :

This micro-project successfully demonstrates the implementation of RSA encryption and


decryption, highlighting its role in secure communication and data protection. Through key
generation, encryption, and decryption processes, we have explored the mathematical foundations
and practical applications of RSA. This project enhances cryptography knowledge, programming
skills, and cybersecurity awareness, preparing learners for real-world security challenges.

VIVA COLLEGE OF DIPLOMA ENGG & TECH, Artificial Intelligence & Machine Learning . 19

You might also like