To implement RSA encryption-decryption in C. (WITH OUTPUT IMAGE)



#include<stdio.h>
#include<conio.h>
#include<math.h>

int mod(int a,int b,int c)
{
   double x=1,div1,div,inte;
   int i;
   float mod1;

   for(i=1;i<=b;i++)
   {x=x*a;}
// printf("\n Exponent is %lf",x);

 div1=x/c;
 div=modf(div1,&inte);
// printf("\n devided %lf",div1);
//printf("\n div %lf",div);

 mod1=div*c;
// mod1=ceill(mod1);
 return mod1;
}


void main()
{
int i,q,p,e,d,n,c[6],dc[6],m[6];
clrscr();

printf("Enter prime number p::");
scanf("%d",&p);

printf("\nEnter prime number q::");
scanf("%d",&q);

printf("\n Enter e::");
scanf("%d",&e);
//printf("%d",xa);
printf("\n Enter d::");
scanf("%d",&d);


n=p*q;

printf("\n ENTER PlAIN TEXT::");
for(i=0;i<6;i++)
scanf("%d",&m[i]);
//ENCRYPTION.
for(i=0;i<6;i++)
{c[i]=mod(m[i],e,n);
printf("\n::::::CIPHER TEXT is::::%d",c[i]);
}

//DECRYPTION.
for(i=0;i<6;i++)
{dc[i]=mod(c[i],d,n);
printf("\n:::::DECRYPTED TEXT is::%d",dc[i]);
}

getch();

}

OUTPUT:

Comments