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

Asim Rsa Cipher

The document is a lab task submission that implements the RSA cipher encryption and decryption algorithm. It includes the code to: 1) Calculate the public and private keys using prime numbers p and q. 2) Encrypt a message by exponentiating it to the public key and taking the modulus of the result with respect to n. 3) Decrypt the ciphertext by exponentiating it to the private key and taking the modulus of the result with respect to n, recovering the original message.

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 PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views3 pages

Asim Rsa Cipher

The document is a lab task submission that implements the RSA cipher encryption and decryption algorithm. It includes the code to: 1) Calculate the public and private keys using prime numbers p and q. 2) Encrypt a message by exponentiating it to the public key and taking the modulus of the result with respect to n. 3) Decrypt the ciphertext by exponentiating it to the private key and taking the modulus of the result with respect to n, recovering the original message.

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 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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy