Exemplo n.º 1
0
        /// <summary>
        /// Tests all trinomials of degree (n+1) until a irreducible is found and stores the result in <c>field polynomial</c>.
        /// Returns false if no irreducible trinomial exists in GF(2^n). This can take very long for huge degrees.
        /// </summary>
        ///
        /// <returns>Returns true if an irreducible trinomial is found</returns>
        private bool TestTrinomials()
        {
            int  i, l;
            bool done = false;

            l = 0;

            FieldPoly = new GF2Polynomial(DegreeN + 1);
            FieldPoly.SetBit(0);
            FieldPoly.SetBit(DegreeN);
            for (i = 1; (i < DegreeN) && !done; i++)
            {
                FieldPoly.SetBit(i);
                done = FieldPoly.IsIrreducible();
                l++;
                if (done)
                {
                    _isTrinomial = true;
                    _tc          = i;
                    return(done);
                }
                FieldPoly.ResetBit(i);
                done = FieldPoly.IsIrreducible();
            }

            return(done);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Tests all pentanomials of degree (n+1) until a irreducible is found and stores the result in <c>field polynomial</c>.
        /// Returns false if no irreducible pentanomial exists in GF(2^n).
        /// This can take very long for huge degrees.
        /// </summary>
        ///
        /// <returns>Returns true if an irreducible pentanomial is found</returns>
        private bool TestPentanomials()
        {
            int  i, j, k, l;
            bool done = false;

            l = 0;

            FieldPoly = new GF2Polynomial(DegreeN + 1);
            FieldPoly.SetBit(0);
            FieldPoly.SetBit(DegreeN);

            for (i = 1; (i <= (DegreeN - 3)) && !done; i++)
            {
                FieldPoly.SetBit(i);
                for (j = i + 1; (j <= (DegreeN - 2)) && !done; j++)
                {
                    FieldPoly.SetBit(j);
                    for (k = j + 1; (k <= (DegreeN - 1)) && !done; k++)
                    {
                        FieldPoly.SetBit(k);
                        if (((DegreeN & 1) != 0) | ((i & 1) != 0) | ((j & 1) != 0)
                            | ((k & 1) != 0))
                        {
                            done = FieldPoly.IsIrreducible();
                            l++;
                            if (done)
                            {
                                _isPentanomial = true;
                                _pc[0]         = i;
                                _pc[1]         = j;
                                _pc[2]         = k;
                                return(done);
                            }
                        }
                        FieldPoly.ResetBit(k);
                    }
                    FieldPoly.ResetBit(j);
                }
                FieldPoly.ResetBit(i);
            }

            return(done);
        }
        /// <summary>
        /// Tests all trinomials of degree (n+1) until a irreducible is found and stores the result in <c>field polynomial</c>.
        /// Returns false if no irreducible trinomial exists in GF(2^n). This can take very long for huge degrees.
        /// </summary>
        /// 
        /// <returns>Returns true if an irreducible trinomial is found</returns>
        private bool TestTrinomials()
        {
            int i, l;
            bool done = false;
            l = 0;

            FieldPoly = new GF2Polynomial(DegreeN + 1);
            FieldPoly.SetBit(0);
            FieldPoly.SetBit(DegreeN);
            for (i = 1; (i < DegreeN) && !done; i++)
            {
                FieldPoly.SetBit(i);
                done = FieldPoly.IsIrreducible();
                l++;
                if (done)
                {
                    _isTrinomial = true;
                    _tc = i;
                    return done;
                }
                FieldPoly.ResetBit(i);
                done = FieldPoly.IsIrreducible();
            }

            return done;
        }
        /// <summary>
        /// Tests all pentanomials of degree (n+1) until a irreducible is found and stores the result in <c>field polynomial</c>.
        /// Returns false if no irreducible pentanomial exists in GF(2^n).
        /// This can take very long for huge degrees.
        /// </summary>
        /// 
        /// <returns>Returns true if an irreducible pentanomial is found</returns>
        private bool TestPentanomials()
        {
            int i, j, k, l;
            bool done = false;
            l = 0;

            FieldPoly = new GF2Polynomial(DegreeN + 1);
            FieldPoly.SetBit(0);
            FieldPoly.SetBit(DegreeN);

            for (i = 1; (i <= (DegreeN - 3)) && !done; i++)
            {
                FieldPoly.SetBit(i);
                for (j = i + 1; (j <= (DegreeN - 2)) && !done; j++)
                {
                    FieldPoly.SetBit(j);
                    for (k = j + 1; (k <= (DegreeN - 1)) && !done; k++)
                    {
                        FieldPoly.SetBit(k);
                        if (((DegreeN & 1) != 0) | ((i & 1) != 0) | ((j & 1) != 0)
                            | ((k & 1) != 0))
                        {
                            done = FieldPoly.IsIrreducible();
                            l++;
                            if (done)
                            {
                                _isPentanomial = true;
                                _pc[0] = i;
                                _pc[1] = j;
                                _pc[2] = k;
                                return done;
                            }
                        }
                        FieldPoly.ResetBit(k);
                    }
                    FieldPoly.ResetBit(j);
                }
                FieldPoly.ResetBit(i);
            }

            return done;
        }