简体   繁体   English

NTL 库 GF2X

[英]NTL library GF2X

I am experimenting with the Galois Field using the NTL library.我正在使用 NTL 库试验伽罗华域。 GF2 are the integers mod 2, GF2X are polynomials over GF2 and GF2E is the ring/field extension over GF2 . GF2是整数模2, GF2X超过多项式GF2GF2E是环/字段扩展超过GF2

The problem that I am facing is that I initialize the irreducible polynomial as follows我面临的问题是我初始化不可约多项式如下

GF2X irreduc;
SetCoeff(irreduc, 128, 1);
SetCoeff(irreduc, 7, 1);
SetCoeff(irreduc, 2, 1);
SetCoeff(irreduc, 1, 1);
SetCoeff(irreduc, 0, 1);
GF2E::init(irreduc);

and then I also initialize two polynomials:然后我还初始化了两个多项式:

GF2X a; 
SetCoeff(a, 120);
SetCoeff(a, 22);

GF2X b;
SetCoeff(b, 128);
SetCoeff(b, 51);

std::cout << "a: " << a << '\n';
std::cout << "b: " << b << '\n';

and multiply them:并将它们相乘:

std::cout << "\ndeg(a * b): " << deg(a * b) << '\n';

The output is deg(a * b): 248 , which is out of the field/ring of the 2^128 , defined by the irreducible polynomial.输出是deg(a * b): 248 ,它在2^128的域/环之外,由不可约多项式定义。

I know that I am probably missing something obvious but I am very new to this area so bear with me.我知道我可能遗漏了一些明显的东西,但我对这个领域很陌生,所以请耐心等待。

Thank you!谢谢!

As you already said, GF2X represents polynomials over GF2 , so they do not get reduced by the polynomial you initialized GF2E with.正如您已经说过的, GF2X表示GF2多项式,因此它们不会被您初始化 GF2E 的多项式减少。 You need to convert the polynomials to GF2E and then everything works as expected.您需要将多项式转换为GF2E ,然后一切都会按预期进行。

So changing you last line to所以把你的最后一行改成

std::cout << "\ndeg(a * b): " << deg(conv<GF2X>(conv<GF2E>(a) * conv<GF2E>(b))) << '\n';

results in the output结果在输出

deg(a * b): 124

This conversions are pretty ugly.这种转换非常难看。 I'm not sure if there is a better way to do it and the way NTL is documented it is hard to find the right functions for what you want to do.我不确定是否有更好的方法来做到这一点,并且 NTL 的记录方式很难找到适合您想要做的事情的正确功能。 I only found GF2E::degree() , but this only gives you the degree if the irreducible polynomial.我只找到了GF2E::degree() ,但这只会给你不可约多项式的度数。 Let me know when you find the right way to do it.当您找到正确的方法时,请告诉我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM