gpt4 book ai didi

c++ - 我是否必须将非标准库包含到 C++ 中的类定义中?

转载 作者:行者123 更新时间:2023-11-28 06:52:57 28 4
gpt4 key购买 nike

<分区>

我是 C++ 编码和一般编码的初学者。我已经成功编写了一段代码来计算 RSA 算法的输出 C,其中 m 是十进制,相当于一个线性反馈移位寄存器的输出。我已将代码放在一个类中,以便我可以多次使用它。编译时,我收到如下错误通知:“‘keyReg’未命名类型 keyReg.push_back(inpSeq[0]);"这段代码在主类的时候,编译的时候并没有出现这样的错误,完整代码如下:

#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <boost/dynamic_bitset.hpp>

using namespace std;

class lfsr {
int y, xx, polyLoc, n, end, f, e, m, c, l, g;
boost::dynamic_bitset<> inpSeq(5);
boost::dynamic_bitset<> operSeq(5);
boost::dynamic_bitset<> bit(5);
vector <int> xorArray;
vector <int> keyReg;
polyLoc = 320;
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[seq_end] = operSeq[x];
y = xorArray[r];
bit[seq_end] = bit[seq_end] ^ operSeq[y];
}
operSeq >>= 1;
operSeq[seq_end] = bit[seq_end];
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;
public:
rsa (int, int, int, boost::dynamic_bitset);
int key () { return (c); }
};
lfsr::lfsr() //Constructor
{
y = 0;
turnCount = 0;
xx = 0;
polyLoc = 0;
n = 0;
end = 0;
f = 0;
e = 0;
m = 0;
c = 0;
l = 0, g = 0;
};
lfsr::rsa (int x, int y, int z, boost::dynamic_bitset <5> initSeq)
{
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;
}

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com