我正在尝试研究与有限域算术相关的部分 NTL 功能,但发生了一些奇怪的事情。我正在尝试在 $GF(2^8)$ 字段中生成 2 个随机元素,并对它们进行加法和减法。但似乎我获得的两个“随机”元素在测试程序的每次执行中都是相等的。你有什么想法吗?
我的测试代码:
void test3(long n) {
NTL::GF2X P;
NTL::BuildIrred(P, n);
// P is now x^2+x+1, this is irreducable since P(1)=1 and P(0)=1
NTL::GF2E::init(P);
NTL::GF2E xx = NTL::random_GF2E();
NTL::GF2E yy = NTL::random_GF2E();
std::cout << "xx: " << xx << std::endl; // Prints something like "[0 1]"
std::cout << "yy: " << yy << std::endl; // Prints something like "[0 1]"
xx += yy;
std::cout << "xx: " << xx << std::endl; // Prints something like "[0 1]"
xx -= yy;
std::cout << "xx: " << xx << std::endl; // Prints something like "[0 1]"
xx -= yy;
std::cout << "xx: " << xx << std::endl; // Prints something like "[0 1]"
}
多次运行测试程序的输出:
~\Release>test.exe
xx: [0 1 0 0 1 0 0 1]
yy: [0 1 0 0 1]
xx: [0 0 0 0 0 0 0 1]
xx: [0 1 0 0 1 0 0 1]
xx: [0 0 0 0 0 0 0 1]
~\Release>test.exe
xx: [0 1 0 0 1 0 0 1]
yy: [0 1 0 0 1]
xx: [0 0 0 0 0 0 0 1]
xx: [0 1 0 0 1 0 0 1]
xx: [0 0 0 0 0 0 0 1]
~\Release>test.exe
xx: [0 1 0 0 1 0 0 1]
yy: [0 1 0 0 1]
xx: [0 0 0 0 0 0 0 1]
xx: [0 1 0 0 1 0 0 1]
xx: [0 0 0 0 0 0 0 1]
~\Release>test.exe
xx: [0 1 0 0 1 0 0 1]
yy: [0 1 0 0 1]
xx: [0 0 0 0 0 0 0 1]
xx: [0 1 0 0 1 0 0 1]
xx: [0 0 0 0 0 0 0 1]