degree of poly is always larger than of the element

This commit is contained in:
Ahmet Inan 2023-04-21 09:00:19 +02:00
commit 595cf80cc5

View file

@ -393,14 +393,19 @@ GaloisFieldReference<M, POLY, TYPE> rcp(GaloisFieldReference<M, POLY, TYPE> a)
{
assert(a.v);
#if 1
uint32_t r = POLY, newr = a.v;
uint32_t t = 0, newt = 1;
if (a.v == 1)
return a;
uint32_t newr = POLY, r = a.v;
uint32_t newt = 0, t = 1;
auto degree = [](uint32_t a) {
int d = 0;
while (a >>= 1)
++d;
return d;
};
int j = M - degree(r);
newr ^= r << j;
newt ^= t << j;
while (newr != 1) {
int j = degree(newr) - degree(r);
if (j < 0) {