Practical 1[1]
Practical 1[1]
:230843116012
PRACTICAL – 1
AIM:-Implement RSA algorithm.
Take two prime numbers p,q
n=pxq
Initially take encryption key such that it is relatively prime with ф(n).
Find out decryption key.
Take plaintext message M, Ciphertext C=Me mod n.
To get plaintect from ciphertext M=Cd mod n.
Test case :
Two prime numbers 17,11
Encryption key = 7
Decryption key = 23
M=88
C=11
CODE:-
#include<stdio.h>
int gcd(int a, int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int modInverse(int e, int phi) {
int t1 = 0, t2 = 1;
int r1 = phi, r2 = e;
while (r2 > 0) {
int quotient = r1 / r2;
int temp_r = r1 % r2;
int temp_t = t1 - quotient * t2;
r1 = r2;
r2 = temp_r;
t1 = t2;
t2 = temp_t;
}
if (r1 > 1) {
printf("No modular inverse exists\n");
return -1;
}
if (t1 < 0) {
t1 += phi;
}
return t1;
}
1
Enrollment No.:230843116012
2
Enrollment No.:230843116012
return 0;
}
OUTPUT