以下函数声明在使用g ++编译时出错:
void lfsr::rsa (int x, int y, int z, boost::dynamic_bitset<> initSeq(5))
错误是:expected ‘,’ or ‘...’ before ‘(’ token
以下是整个代码:
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <boost/dynamic_bitset.hpp>
using namespace std;
class lfsr
{
int y, xx, polyLoc, turnCount, n, end, p, q, d, f, e, m, c, l, g;
boost::dynamic_bitset<> inpSeq;
boost::dynamic_bitset<> operSeq;
boost::dynamic_bitset<> bit;
vector<int> xorArray;
vector<int> keyReg;
public:
void rsa(int, int, int, boost::dynamic_bitset<>);
int key()
{
while (polyLoc > 0)
{
xorArray.push_back(polyLoc % 10);
polyLoc /= 10;
}
sort(xorArray.rbegin(), xorArray.rend());
operSeq = inpSeq;
keyReg.push_back(inpSeq[0]);
int 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]);
turnCount++;
}
while ((operSeq != inpSeq) && (turnCount < 1024));
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 (int k = 0; end < 1; k++)
{
if ((1 + k * f) % d == 0)
{
end = 2;
e = (1 + (k * f)) / d;
}
}
g = int(pow(m, e));
c = g % n;
return (c);
}
};
lfsr() // Constructor
{
y = 0;
turnCount = 0;
xx = 0;
polyLoc = 320;
n = 0;
end = 0;
p = 0;
q = 0;
d = 0;
f = 0;
e = 0;
m = 0;
c = 0;
l = 0, g = 0;
boost::dynamic_bitset<> inpSeq(5);
boost::dynamic_bitset<> operSeq(5);
boost::dynamic_bitset<> bit(5);
}
void lfsr::rsa(int x, int y, int z, boost::dynamic_bitset<> initSeq(5))
{
p = x;
q = y;
d = z;
inpSeq = initSeq;
}
int main()
{
lfsr public_key, private_key;
public_key.rsa(29, 41, 74, 00111);
private_key.rsa(43, 89, 73, 01011);
cout << "Public key is: " << public_key.key() << endl;
cout << "Private key is: " << private_key.key() << endl;
cin.get();
return 0;
}
答案 0 :(得分:0)
更改此代码
lfsr() //Constructor
到
lfsr::lfsr() //Constructor
将构造函数的声明插入到类
中class lfsr {
....
public:
lfsr();
....
将定义中的initSeq1
的默认参数移至声明。 (必须在声明中。)
此外,您的默认参数是错误的。它应该是initSeq = boost::dynamic_bitset<>(5)
更改此代码
class lfsr {
....
public:
void rsa (int, int, int, boost::dynamic_bitset <>);
....
};
void lfsr::rsa (int x, int y, int z, boost::dynamic_bitset <> initSeq(5))
{
...
到
class lfsr {
....
public:
void rsa (int, int, int, boost::dynamic_bitset<> = boost::dynamic_bitset<>(5));
....
};
void lfsr::rsa (int x, int y, int z, boost::dynamic_bitset<> initSeq)
{
...