Hi everyone..I tried RSA algorithm by using C language and I got the
correct output also. My query is *are there more number of methods to
implement RSA algorithm in C language*??
The logic of the code goes like this:
1) Pick two large prime numbers p and q, p != q;
2) Calculate n = p × q;
3) Calculate ø (n) = (p − 1)(q − 1);
4) Pick e, so that gcd(e, ø (n)) = 1, 1 < e < ø (n);
5) Calculate d, so that d · e mod ø (n) = 1, i.e., d is the multiplicative
inverse of e in mod ø (n);
6) Get public key as KU = {e, n};
7) Get private key as KR = {d, n}.
*Encryption*
For plaintext block P < n, its ciphertext C = P^e (mod n).
*Decryption*
For ciphertext block C, its plaintext is P = C^d (mod n).
My code goes like this:
#include<stdio.h>
#include<conio.h>
int phi,d,flag,C,T,n,e;
int eval(int e1);
{
printf("e value is:%d",e1);
for(int k=3;e1%k==0 && phi%k==0;k++)
{
flag=1;
return(1);
}
flag=0;
return(1);
}
void encrypt()
{
int C=(T^e)%n;
printf("\nencrypted data is:%d",C);
}
void decrypt()
{
int T=(C^e)%n;
printf("\ndecrypted data is:%d",T);
}
int main()
{
int p=17,q=29,s;
//clrscr();
//printf("\nenter first prime number here:");
//scanf("%d",&p);
//printf("\nenter second prime number here:");
//scanf("%d",&q);
n=p*q;
printf("\nn value is:%d",n);
phi=(p-1)*(q-1);
printf("\nphi value is:%d",phi);
do
{
e=31;
printf("e value is:%d",e);
eval(e);
}while(flag==1);
int d=1;
do
{//
s=(e*d)%phi;
d++;
}while(s!=1);
d=d-1;
printf("\npublic key is:{%d,%d}",e,n);
printf("\nprivate key is:{%d,%d}",d,n);
printf("\nenter you text here");
scanf("%d",&T);
encrypt();
printf("\nenter cipher text here");
scanf("%d",&C);
decrypt();
//getch();
return 0;
}
Here at first I wrote p,q values manually but i got an error. Thats why I
assigned values to p and q directly.
Please tell me are there any more number of methods to implement RSA
algorithm in C language.
7h4nk Y0u.... :-)
--
You received this message because you are subscribed to the Google Groups
"NFORCEIT" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send an email to [email protected].
Visit this group at http://groups.google.com/group/nforceit.
For more options, visit https://groups.google.com/d/optout.