#include <string.h>
#include <conio.h>
#include <math.h>
int mult(unsigned int x, unsigned int y, unsigned int n) {
unsigned long int k = 1;
int j;
for (j = 1; j <= y; j++)
k = (k * x) % n;
return (unsigned int) k;
}
void main() {
char msg[100];
unsigned int pt[100], ct[100], n, d, e, p, q, i;
printf("Enter message : ");
gets(msg);
//strcpy(pt, msg);
for (i = 0; i < strlen(msg); i++)
pt[i] = msg[i];
n = 253;
d = 17;
e = 13;
printf("\nCT = ");
for (i = 0; i < strlen(msg); i++)
ct[i] = mult(pt[i], e, n);
for (i = 0; i < strlen(msg); i++)
printf("%d ", ct[i]);
printf("\nPT = ");
for (i = 0; i < strlen(msg); i++)
printf("%c", pt[i]);
for (i = 0; i < strlen(msg); i++)
pt[i] = mult(ct[i], d, n);
}
This is simple program for implementing RSA algorithm can anybody explain me what’s happening here and why particularly n=253, d=17 , e=13.
Help would be much appreciated.
http://en.wikipedia.org/wiki/RSA_(algorithm).
253=11*23, // n=253 is product of two “large” primes p,q
phi(n)=10*22=220. // Eulers totient function is calculated from p,q
e= 13 // a small number, that is coprime with phi(n).
Then d is calculated so, that e*d=1 mod 220 –> d=17
-> d*e=221 === 1 mod 220.
Throw p,q away.