Пример #1
0
        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);
        }
Пример #2
0
        static public PolynomZ2 operator -(PolynomZ2 a, PolynomZ2 b)
        {
            PolynomZ2 c = new PolynomZ2();

            c.p = a.p ^ b.p;
            return(c);
        }
Пример #3
0
 public static PolynomZ2 GCD(PolynomZ2 a, PolynomZ2 b)
 {
     if (b.p == 0)
     {
         return(a);
     }
     else
     {
         return(GCD(b, a % b));
     }
 }
Пример #4
0
        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);
        }
Пример #5
0
        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);
        }
Пример #6
0
        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);
        }
Пример #7
0
        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;
        }
Пример #8
0
 public PolynomZ2(PolynomZ2 a)
 {
     p = a.p;
 }