public static PolynomZ2 GenerateIrreducablePolynomZ2(int m) { //random Polynom bool found = false; PolynomZ2 f; do { Random r = new Random(); f = new PolynomZ2((1 + (1 << m))); for (int i = 1; i < m; i++) { f.p |= r.Next(2) << i; } PolynomZ2 u = new PolynomZ2(2); PolynomZ2 d; bool Irreducable = true; for (int i = 1; i <= m / 2; i++) { u = u * u % f; d = GCD(f, u - new PolynomZ2(2)); if (d.CompareTo(new PolynomZ2(1)) != 0) { Irreducable = false; } } if (Irreducable) { found = true; } } while (!found); return(f); }
static public PolynomZ2 operator -(PolynomZ2 a, PolynomZ2 b) { PolynomZ2 c = new PolynomZ2(); c.p = a.p ^ b.p; return(c); }
public static PolynomZ2 GCD(PolynomZ2 a, PolynomZ2 b) { if (b.p == 0) { return(a); } else { return(GCD(b, a % b)); } }
public static PolynomZ2 operator %(PolynomZ2 a, PolynomZ2 b) { PolynomZ2 c = new PolynomZ2(a); // остатое PolynomZ2 d = new PolynomZ2(0); // частнок while (c.CompareTo(new PolynomZ2(0)) > 0 && c.Deg >= b.Deg) { d.p |= 1 << (c.Deg - b.Deg); c.p ^= b.p << (c.Deg - b.Deg); } return(c); }
public static PolynomZ2 operator /(PolynomZ2 a, PolynomZ2 b) { PolynomZ2 c = new PolynomZ2(a); // остаток PolynomZ2 d = new PolynomZ2(0); // частнок while (c.Deg >= b.Deg) { d.p |= 1 << (c.Deg - b.Deg); c.p ^= b.p << (c.Deg - b.Deg); } return(d); }
static public PolynomZ2 operator *(PolynomZ2 a, PolynomZ2 b) { PolynomZ2 c = new PolynomZ2(); for (int i = 0; i <= 31; i++) { if ((a.p >> i & 1) == 1) { c.p ^= b.p << i; } } return(c); }
public void xtime() { PolynomZ2 c = new PolynomZ2(); PolynomZ2 b = new PolynomZ2(0x02); for (int i = 0; i <= 31; i++) { if ((this.p >> i & 1) == 1) { c.p ^= b.p << i; } } this.p = c.p; }
public PolynomZ2(PolynomZ2 a) { p = a.p; }