diff --git a/lib/gf2m.cpp b/lib/gf2m.cpp index c802f72..b8858d2 100644 --- a/lib/gf2m.cpp +++ b/lib/gf2m.cpp @@ -119,7 +119,7 @@ uint gf2m::inv (uint a) uint gf2m::sq_root (uint a) { - for (uint i = 0; i < m; ++i) + for (uint i = 1; i < m; ++i) a = mult (a, a); return a; } diff --git a/lib/polynomial.cpp b/lib/polynomial.cpp index 81cf886..50df8ef 100644 --- a/lib/polynomial.cpp +++ b/lib/polynomial.cpp @@ -57,8 +57,9 @@ void polynomial::mod (const polynomial&f, gf2m&fld) uint t = fld.mult (item (d), hi); for (int i = 0; i <= df; ++i) - item (i + d - df) = fld.add (item (i + d - df), - fld.mult (t, f[i]) ); + item (i + d - df) + = fld.add (item (i + d - df), + fld.mult (t, f[i]) ); } strip(); } @@ -192,23 +193,25 @@ for(int c=0;c= 0; --i) + for (i = d - 1; i >= 0; --i) { for (j = 0; j < i; ++j) { a = l[i][j]; if (a == 0) continue; add_row_mult (i, j, a); } + } + return true; } @@ -282,8 +285,19 @@ void polynomial::sqrt (vector& sqInv, gf2m&fld) { polynomial a = *this; clear(); - for (uint i = 0; i < a.size(); ++i) add_mult (sqInv[i], a[i], fld); - for (uint i = 0; i < size(); ++i) item (i) = fld.sq_root (item (i) ); + uint s=sqInv.size(); + resize (s, 0); + + for (uint i = 0; i < s; ++i) { + for (uint j = 0; j < s; ++j) { + if (j >= a.size() ) break; + if (i >= sqInv[j].size() ) continue; + item (i) = fld.add (item (i), fld.mult (sqInv[j][i], a[j]) ); + } + } + strip(); + for (uint i = 0; i < size(); ++i) + item (i) = fld.sq_root (item (i) ); } void polynomial::div (polynomial&p, polynomial&m, gf2m&fld)