RSA implementation in C for words..

/* This program encrypts words using RSA algorithms */
#include<stdio.h>
#include<string.h>

int phi,M,n,e,d,C,FLAG;
char msg[20];
unsigned int cip[20],dec[20];
int check()
{
int i;
for(i=3;e%i==0 && phi%i==0;i+2)
{
FLAG = 1;
return;
}
FLAG = 0;
}

void encrypt()
{
int i,q;
C = 1;
//for(q=0;qprintf("\n\tEncrypted keyword :");
for(q=0;q{
    C=1;
M=msg[q];
//printf("\n\tcrypted keyword : %d",M);
for(i=0;i< e;i++)
C=C*M%n;
C= C%n;
cip[q]=C;
printf("%d  ",cip[q]);
}
cip[q]='\0';
//}
}


void decrypt()
{
int i,q;
M = 1;
printf("\nDecrypted keyword :");
for(q=0;q
{
    M=1;
 C=cip[q];
//printf("\nDEDE keyword : %d",cip[q]);
for(i=0;i< d;i++)
M=M*C%n;
M = M%n;
dec[q]=M;
printf(" %c",dec[q]);
}
}

void main()
{
int p,q,s;

printf("Enter Two Relatively Prime Numbers\t: ");
//scanf("%d%d",&p,&q);
p=11;q=17;
n = p*q;
phi=(p-1)*(q-1);
printf("\n\tF(n)\t= %d",phi);
do
{
printf("\n\nEnter e\t: ");
//scanf("%d",&e);
e=7;
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("%s",msg);
//printf("\n\nEnter The Plain Text\t: ");
//scanf("%d",&M);
encrypt();
//printf("\n\nEnter the Cipher text\t: ");
//printf("\n\nEnter the Cipher text\t: ");
//scanf("%s",cip);
//scanf("%d",&C);
decrypt();

}




Enter your email address:
Delivered by FeedBurner

No comments: