I am trying to implement RSA using a C++ class. Below is the program :
#include<math.h>
#include<iostream>
#include<cmath>
#include<Windows.h>
#include <algorithm>
using namespace std;
class rsacrypto
{
long publickey;
long privatekey;
long modl;
public :
rsacrypto(); rsacrypto(long &,long &,long &); rsacrypto(long key,long modulus) {
publickey = privatekey = key;
modl = modulus;
}
long ret_publickey()
{
return publickey;
}
long ret_privatekey()
{
return privatekey;
}
long ret_modulus()
{
return modl;
}
void encrypt(char *);
void decrypt(char *);
int genrndprimes(int, int);
int totient(int);
int genrndnum(int, int);
};
rsacrypto::rsacrypto()
{
long p1,p2; long n = 0; long phi =0;
long e = 0; long d = 0;
p1 = genrndprimes(100,900);
Sleep(1000);
p1 = genrndprimes(100,900);
n = p1*p2;
phi = totient(n);
e = genrndnum(2,(phi-1));
while(std::__gcd(e,phi)!=1)
{
e = genrndnum(2,(phi-1));
}
d = (1/e)%phi;
privatekey = e;
publickey = d;
modl = n;
}
rsacrypto::rsacrypto(long &pubkey,long &privkey,long &mdls)
{
long p1,p2; long n = 0; long phi =0;
long e = 0; long d = 0;
p1 = genrndprimes(100,900);
Sleep(1000);
p1 = genrndprimes(100,900);
n = p1*p2;
phi = totient(n);
e = genrndnum(2,(phi-1));
while(std::__gcd(e,phi)!=1)
{
e = genrndnum(2,(phi-1));
}
d = (1/e)%phi;
privatekey = e;
publickey = d;
pubkey = publickey;
privkey = privatekey;
mdls = n;
modl = n;
}
void rsacrypto::encrypt(char *dat)
{
long siz = strlen(dat);
for(long i=0;i<siz;i++)
{
dat[i]=(long)pow(dat[i],publickey)%modl;
}
}
void rsacrypto::decrypt(char *datn)
{
long sizz = strlen(datn);
for(long i=0;i<sizz;i++)
{
datn[i]=(long)pow(datn[i],privatekey)%modl;
}
}
void main()
{
char datm[]="Hello!! , Implementing RSA";
rsacrypto m;
long prkey = m.ret_privatekey();
long publkey = m.ret_publickey();
long modulm = m.ret_modulus();
rsacrypto jj(publkey,modulm);
rsacrypto ll(prkey,modulm);
jj.encrypt(datm);
puts(datm);
cout<<"\n";
ll.decrypt(datm);
puts(datm);
}
I face problem in line 125 (dat[i]=(long)pow(dat[i],publickey)%modl;)
and this error appear in compile:
call of overloaded `pow(char&, long int&)' is ambiguous
please help me to solve this error