im trying to implement the RSA encryption algorithm however for some reason the code's not running; am i missing something?
the code :
#define fastio ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define pii pair<int,int>
#define ll long long
#include <bits/stdc++.h>
using namespace std;
//public key cryptography
ll modexp(ll base, ll exp, ll mod){
ll ans=1;
base%=mod;
while(exp>0){
if(exp&1) ans=(ansbase)%mod;
base=(basebase)%mod;
exp>>=1;
}
return ans;
}
bool isPrime(ll num){
if(num<2) return false;
for(int i=2;i*i<=num;i++){
if(num%i==0) return false;
}
return true;
}
void rsa(ll num,ll p,ll q){
ll n=pq;
ll eulerTotient=(p-1)(q-1);
ll E,D;
//public key E such that 1<E<eulerTotient and gcd(E,eulerTotient)=1
for(ll i=2;i<eulerTotient;i++){
if(__gcd(i,eulerTotient)==1){
E=i;
break;
}
}
cout<<"Public key : "<<E<<endl;
//getting private key
for(ll i=2;i<eulerTotient;i++){
if(((i*E)%eulerTotient)==1){
D=i;
break;
}
}
cout<<"Private key : "<<D<<endl;
ll cyphr, dcrypt;
cyphr=modexp(num,E,n);
cout<<"Encrypted number : "<<cyphr<<endl;
dcrypt=modexp(cyphr,D,n);
cout<<"Decrypted number : "<<dcrypt<<endl;
}
int main(){
fastio;
ll p,q;
cout<<"Enter p : ";
cin>>p;
if(!isPrime(p)){
cout<<"p is not prime.";
return -1;
}
cout<<"Enter q : ";
cin>>q;
if(!isPrime(q)){
cout<<"q is not prime.";
return -1;
}
ll pt;
cout<<"Enter value to encrypt : ";
cin>>pt;
rsa(pt,p,q);
return 0;
}