The following code doesn't compile, I am sure the problem is with how I declare and assign values to the dynamic bitset inpSeq, for assigning bits to that bit set, I coded like this
usr1.set (11, 5, 23, 00001);
For declaring inpSeq in the member function set I used:
void set (int , int , int, boost::dynamic_biset <>);
Also the declaration of the other 3 dynamic bitsets is somehow wrong I don't know why, I declared them as if they were in main, don't know if or how it is different in a class.
Here is the full code:
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <boost/dynamic_bitset.hpp>
using namespace std;
class rsa {
protected:
int polyLoc, x, y, p, q, d, m, n, f, e, c, end, k;
boost::dynamic_bitset<> inpSeq (5);
boost::dynamic_bitset<> operSeq(5);
boost::dynamic_bitset<> bit(5);
vector <int> xorArray;
vector <int> keyReg;
public:
rsa () : polyLoc(3210), x(0), y(0), n(0), e(0), c(0), k(0), end(0), f(0) {};
void set (int , int , int, boost::dynamic_biset <>);
int key () {
while(polyLoc>0)
{
xorArray.push_back(polyLoc%10);
polyLoc/=10;
}
sort(xorArray.rbegin(), xorArray.rend());
operSeq = inpSeq;
keyReg.push_back(inpSeq[0]);
x = xorArray[0];
do {
for (unsigned int r = 1; r < xorArray.size(); r++)
{
bit[4] = operSeq[x];
y = xorArray[r];
bit[4] = bit[4] ^ operSeq[y];
}
operSeq >>= 1;
operSeq[4] = bit[4];
keyReg.push_back(operSeq[0]);
}
while ((operSeq != inpSeq));
for ( unsigned int i = 0; i < keyReg.size(); i++)
{
if (keyReg[i]==1)
m = m + int(pow(2,i));
}
n = p*q;
f = (p-1)*(q-1);
for (k ; end < 1; k++)
{
if ((1+k*f)%d==0)
{
end = 2;
e = (1+k*f)/d;
}
}
c = int(pow(m,e))%n;
return c;}
};
void rsa::set(int p_, int q_, int d_, boost::dynamic_biset <> m_ (5))
{
p = p_;
q = q_;
d = d_;
inpSeq = m_;
}
class public_key : public rsa {
public:
public_key () : rsa () {} ;
};
class private_key : public rsa {
public:
private_key () : rsa () {} ;
};
int main()
{
public_key usr1, usr2, usr3;
private_key usr1r, usr2r, usr3r;
usr1.set (11, 5, 23, 00001);
usr2.set (13, 7, 97, 00010);
usr3.set (11, 17, 997, 00011);
usr1r.set (17, 7, 51, 10011);
usr2r.set (11, 17, 51, 10110);
cout << "Public key of user 1: " << usr1.key() << endl;
cout << "Public key of user 2: " << usr2.key() << endl;
cout << "Public key of user 3: " << usr3.key() << endl;
cin.get();
return 0;
}
Errors were: expected identifier before numeric constant
boost::dynamic_bitset<> inpSeq(5);
^
damage.cc:11:33: error: expected ‘,’ or ‘...’ before numeric constant
damage.cc:12:34: error: expected identifier before numeric constant
boost::dynamic_bitset<> operSeq(5);
^
damage.cc:12:34: error: expected ‘,’ or ‘...’ before numeric constant
damage.cc:13:30: error: expected identifier before numeric constant
boost::dynamic_bitset<> bit(5);
^
damage.cc:13:30: error: expected ‘,’ or ‘...’ before numeric constant
damage.cc:18:36: error: ‘boost::dynamic_biset’ has not been declared
void set (int , int , int, boost::dynamic_biset <>);
^
damage.cc:18:50: error: expected ‘,’ or ‘...’ before ‘<’ token
void set (int , int , int, boost::dynamic_biset <>);
^
damage.cc: In member function ‘int rsa::key()’:
damage.cc:26:10: error: invalid use of member function (did you forget the ‘()’ ?)
operSeq = inpSeq;
^
damage.cc:27:27: error: invalid types ‘<unresolved overloaded function type>[int]’ for array subscript
keyReg.push_back(inpSeq[0]);
^
damage.cc:32:8: error: invalid types ‘<unresolved overloaded function type>[int]’ for array subscript
bit[4] = operSeq[x];
^
damage.cc:32:21: error: invalid types ‘<unresolved overloaded function type>[int]’ for array subscript
bit[4] = operSeq[x];
^
damage.cc:34:8: error: invalid types ‘<unresolved overloaded function type>[int]’ for array subscript
bit[4] = bit[4] ^ operSeq[y];
^
damage.cc:34:17: error: invalid types ‘<unresolved overloaded function type>[int]’ for array subscript
bit[4] = bit[4] ^ operSeq[y];
^
damage.cc:34:30: error: invalid types ‘<unresolved overloaded function type>[int]’ for array subscript
bit[4] = bit[4] ^ operSeq[y];
^
damage.cc:36:11: error: invalid use of member function (did you forget the ‘()’ ?)
operSeq >>= 1;
^
damage.cc:37:12: error: invalid types ‘<unresolved overloaded function type>[int]’ for array subscript
operSeq[4] = bit[4];
^
damage.cc:37:22: error: invalid types ‘<unresolved overloaded function type>[int]’ for array subscript
operSeq[4] = bit[4];
^
damage.cc:38:29: error: invalid types ‘<unresolved overloaded function type>[int]’ for array subscript
keyReg.push_back(operSeq[0]);
^
damage.cc:40:21: error: invalid use of member function (did you forget the ‘()’ ?)
while ((operSeq != inpSeq));
^
damage.cc:40:21: error: invalid use of member function (did you forget the ‘()’ ?)
damage.cc: At global scope:
damage.cc:60:46: error: ‘boost::dynamic_biset’ has not been declared
void rsa::set(int p_, int q_, int d_, boost::dynamic_biset <> m_ (5))
^
damage.cc:60:60: error: expected ‘,’ or ‘...’ before ‘<’ token
void rsa::set(int p_, int q_, int d_, boost::dynamic_biset <> m_ (5))
^
damage.cc: In member function ‘void rsa::set(int, int, int, int)’:
damage.cc:65:12: error: ‘m_’ was not declared in this scope
inpSeq = m_;
You need to initialize the dynamic_bitset
members in the member initialization list
.
class rsa
{
public:
typedef boost::dynamic_bitset<> BitSet;
protected:
int polyLoc, x, y, p, q, d, m, n, f, e, c, end, k;
BitSet inpSeq;
BitSet operSeq;
BitSet bit;
vector <int> xorArray;
vector <int> keyReg;
public:
rsa () : polyLoc(3210), x(0), y(0), n(0), e(0), c(0), k(0), end(0), f(0),
inpSeq(5), operSeq(5), bit(5) {}
void set (int , int , int, const BitSet&);
//...
};
Whenever you have a member that requires anything other than default construction, you must initialize it in the member-init list. The change I made above was to use a convenient typedef called BitSet
. This change may make things more clearer to you as to how to handle types that require initialization.