Hi Dear Friends,
I am looking for a good C program for RSA Algoritm implementation, but my current program is buggy
eg: when I give two prime numbers(p&q) as 11 and 3
and public key (e) as 5
according to RSA i got wrong answer
please help me to correct this issue My code is:
Here the "Check()" function is not do anything valuable .
Please help me to remove this issue
I am looking for a good C program for RSA Algoritm implementation, but my current program is buggy
eg: when I give two prime numbers(p&q) as 11 and 3
and public key (e) as 5
according to RSA i got wrong answer
please help me to correct this issue My code is:
Code:
#include<stdio.h> #include<conio.h> int phi,C,M,n,e,d,FLAG; int check() { int i; for(i=3;e%i==0&&phi%i==0;i+2) { FLAG = 1; return ; } FLAG = 0; } void encrypt() { int i; C = 1; for(i=0;i<e;i++) C=C*M%n; C = C%n; printf("\\n\tEncrypted keyword: %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 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 is \t: {%d, %d}",e,n); printf("\n\tPrivate key is\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(); }
Please help me to remove this issue
Comment