[go: up one dir, main page]

0% found this document useful (0 votes)
54 views3 pages

Tayyab Abdullah Rsa Cipher

The document is a lab task submission that implements RSA cipher encryption and decryption. It includes: 1) Code to calculate the greatest common divisor (GCD) of two numbers. 2) Main code that defines prime numbers p and q, calculates n as their product, and phi as (p-1)*(q-1). It finds an e value coprime to phi. 3) The code encrypts a message m by computing c = (m^e) mod n, and decrypts by computing m = (c^d) mod n, where d is the modular inverse of e.

Uploaded by

Amna Arooj
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)
54 views3 pages

Tayyab Abdullah Rsa Cipher

The document is a lab task submission that implements RSA cipher encryption and decryption. It includes: 1) Code to calculate the greatest common divisor (GCD) of two numbers. 2) Main code that defines prime numbers p and q, calculates n as their product, and phi as (p-1)*(q-1). It finds an e value coprime to phi. 3) The code encrypts a message m by computing c = (m^e) mod n, and decrypts by computing m = (c^d) mod n, where d is the modular inverse of e.

Uploaded by

Amna Arooj
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/ 3

DATA SECURITY AND APPLICATIONS

LAB TASK

Submitted By

Ahmed Asim Zaman (F-301012)

Class: BSSE-3 (7th Semester)

Instructor Name
Engr. Fahim Muhammad Khan

Submission Date: 03rd-Jan-2024


LAB TASK
IMPLEMENTATION OF RSA CIPHER
OUTPUT

CODE
#include <stdio.h>
#include <math.h>

double gcd(double a, double h) {


double temp;
while (1) { temp =
fmod(a, h); if
(temp == 0)
return h; a = h;
h = temp;
}}

int main()
{ double p = 3;
double q = 7;
double n = p * q;
double e = 2;
double phi = (p - 1) * (q - 1);

while (e < phi)


{ if (gcd(e, phi) ==
1)
break;
else
e++;
}

int k = 2;
double d = (1 + (k * phi)) / e;

double msg = 12;

printf("Message data = %.6f\n", msg);

// Encryption c = (msg ^ e) % n
double c = fmod(pow(msg, e), n);
printf("Encrypted data = %.6f\n", c);

// Decryption m = (c ^ d) % n
double m = fmod(pow(c, d), n);
printf("Original Message Sent = %.6f\n", m);

return 0;
}

You might also like