-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRSA.C
More file actions
executable file
·66 lines (63 loc) · 948 Bytes
/
RSA.C
File metadata and controls
executable file
·66 lines (63 loc) · 948 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*RSA Algorithm*/
#include<stdio.h>
#include<conio.h>
int phi,M,n,e,d,C,FLAG;
int check()
{
int i;
for(i=3;e%i==0 && phi%i==0;i+2)
{
FLAG=1;
return;
}
FLAG=0;
return;
}
void encrypt()
{
int i;
C=1;
for(i=0;i<e;i++)
C=C*M%n;
C=C%n;
printf("\n\tEncrypt keyboard : %d",C);
}
void decrypt()
{
int i;
M=1;
for(i=0;i<d;i++)
M=M*C%n;
M=M%n;
printf("\n\tDecrypted keyword : %d",M);
}
void main()
{
int p,q,s;
clrscr();
printf("Enter Two Relatively Prime Numbers\t:");
scanf("%d%d",&p,&q);
n=p*q;
phi=(p-1)*(q-1);
printf("\n\tF(n)\t=%d",phi);
do{
printf("\n\nEnter e\t:");
scanf("%d",&e);
check();
}while(FLAG==1);
d=1;
do{
s=(d*e)%phi;
d++;
}while(s!=1);
d=d-1;
printf("\n\tPublic Key\t:{%d,%d}",e,n);
printf("\n\tPrivate Key\t:{%d,%d}",d,n);
printf("\n\nEnter The Plain Text\t:");
scanf("%d",&M);
encrypt();
printf("\n\nEnter the Cipher text\t:");
scanf("%d",&C);
decrypt();
getch();
}