123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- #include<iostream>
- #include<cmath>
- using namespace std;
- long double find_pow(long double a,long double b, long double c)
- {
- long double i,final=1;
- for(i=0;i<b;i++)
- final=fmodl(final*fmodl(a,c),c);
- return fmodl(final,c);
- }
- long double find_d(long double e,long double phi_of_n)
- {
- int i;
- e=fmodl(e,phi_of_n);
-
- for(i=0;i<phi_of_n;i++)
- if(fmodl((e*i),phi_of_n)==1)
- break;
-
- return i;
- }
- int main()
- {
- long double M,p,q,e,n,phi_of_n,C,d;
- cout<<"\nEnter the plain text\n";
- cin>>M;
-
- cout<<"\nEnter the two prime numbers\n";
- cin>>p>>q;
-
- cout<<"\nEnter e\n";
- cin>>e;
-
- n=p*q;
-
- phi_of_n = (p-1)*(q-1);
- C=find_pow(M,e,n);
- cout<<"\nEncrypted Text is "<<C;
-
- d=find_d(e,phi_of_n);
-
- M=find_pow(C,d,n);
- cout<<"\nDecrypted Text is "<<M<<endl;
-
- return 0;
- }
- /*
- OUTPUT:-
-
- Enter the plain text
- 88
-
- Enter the two prime numbers
- 17 11
-
- Enter e
- 7
-
- Encrypted Text is 11
- Decrypted Text is 88
-
- */
|