#### RSA C program

##### rsa.txt

##### File size: 1.09 KB

**File content type:**
text/plain

**Category: **Notes, Practical Files, and Assignment

**Course: **B.Tech.

**Semester: **7

```
// C program for RSA asymmetric cryptographic
// algorithm. For demonstration values are
// relatively small compared to practical
// application
#include<stdio.h>
#include<math.h>
// Returns gcd of a and b
int gcd(int a, int h)
{
int temp;
while (1)
{
temp = a%h;
if (temp == 0)
return h;
a = h;
h = temp;
}
}
// Code to demonstrate RSA algorithm
int main()
{
// Two random prime numbers
double p = 3;
double q = 7;
// First part of public key:
double n = p*q;
// Finding other part of public key.
// e stands for encrypt
double e = 2;
double phi = (p-1)*(q-1);
while (e < phi)
{
// e must be co-prime to phi and
// smaller than phi.
if (gcd(e, phi)==1)
break;
else
e++;
}
// Private key (d stands for decrypt)
// choosing d such that it satisfies
// d*e = 1 + k * totient
int k = 2; // A constant value
double d = (1 + (k*phi))/e;
// Message to be encrypted
double msg = 20;
printf("Message data = %lf", msg);
// Encryption c = (msg ^ e) % n
double c = pow(msg, e);
c = fmod(c, n);
printf("\nEncrypted data = %lf", c);
// Decryption m = (c ^ d) % n
double m = pow(c, d);
m = fmod(m, n);
printf("\nOriginal Message Sent = %lf", m);
return 0;
}
```

Added by **passhojao**

##### Comments

*whatshot*Forum*launch*-
Computer Graphics Video Lectures
Posted in

**Semester 3** -
Competitive Programming
Posted in

**Competitive Programming** -
Improve confirmation page during signup
Posted in

**Feature requests** -
Recommended Books BTech first semester GGSIPU Delhi
Posted in

**Semester 1** -
Guidelines for Uploads on PassHoJao
Posted in

**Rules and Instructions**

*file_download*Study Material*launch*-
Sensor and transducers
Catgegory:

**Notes** -
Applied Maths - I (Curvature)
Catgegory:

**Notes** -
Fundamentals Of Computing Internal Examination 2017
Catgegory:

**Question Papers** -
Microprocessors and Microcontrollers MID TERM 2018 MSIT
Catgegory:

**Question Papers** -
IPU CSE 3rd Sem Syllabus
Catgegory:

**Syllabus** -
IPU 6th sem CSE Syllabus
Catgegory:

**Syllabus** -
C program for drawing a CIRCLE using Midpoint Circle Algorithm - CGMT
Catgegory:

**Assignment** -
Electrical Technology Internal Examination 2017
Catgegory:

**Question Papers** -
Bresenham Line Drawing Program in C
Catgegory:

**Assignment** -
computer fundamentals with no missing pages
Catgegory:

**Notes**