Пример #1
0
        /// <summary>
        /// Creates a new PolynomialGF2n of size <c>Degree</c> and elem as coefficients
        /// </summary>
        /// 
        /// <param name="Degree">The maximum degree + 1</param>
        /// <param name="Element">A GF2nElement</param>
        public GF2nPolynomial(int Degree, GF2nElement Element)
        {
            _size = Degree;
            _coeff = new GF2nElement[_size];

            for (int i = 0; i < _size; i++)
                _coeff[i] = (GF2nElement)Element.Clone();
        }
Пример #2
0
        /// <summary>
        /// Sets the coefficient at <c>Index</c> to <c>Element</c>
        /// </summary>
        ///
        /// <param name="Index">The index</param>
        /// <param name="E">The GF2nElement to store as coefficient <c>Index</c></param>
        public void Set(int Index, GF2nElement E)
        {
            if (!(E is GF2nPolynomialElement) && !(E is GF2nONBElement))
            {
                throw new ArgumentException("GF2nPolynomial: PolynomialGF2n.Set f must be an instance of either GF2nPolynomialElement or GF2nONBElement!");
            }

            _coeff[Index] = (GF2nElement)E.Clone();
        }
Пример #3
0
        /// <summary>
        /// Creates a new PolynomialGF2n of size <c>Degree</c> and elem as coefficients
        /// </summary>
        ///
        /// <param name="Degree">The maximum degree + 1</param>
        /// <param name="Element">A GF2nElement</param>
        public GF2nPolynomial(int Degree, GF2nElement Element)
        {
            _size  = Degree;
            _coeff = new GF2nElement[_size];

            for (int i = 0; i < _size; i++)
            {
                _coeff[i] = (GF2nElement)Element.Clone();
            }
        }
Пример #4
0
        /// <summary>
        /// Converts the given element in representation according to this field to a new element in 
        /// representation according to B1 using the change-of-basis matrix calculated by computeCOBMatrix.
        /// </summary>
        /// 
        /// <param name="Elem">The GF2nElement to convert</param>
        /// <param name="Basis">The basis to convert <c>Elem</c> to</param>
        /// 
        /// <returns>Returns <c>Elem</c> converted to a new element representation according to <c>basis</c></returns>
        public GF2nElement Convert(GF2nElement Elem, GF2nField Basis)
        {
            if (Basis == this)
                return (GF2nElement)Elem.Clone();
            if (FieldPoly.Equals(Basis.FieldPoly))
                return (GF2nElement)Elem.Clone();
            if (DegreeN != Basis.DegreeN)
                throw new Exception("GF2nField.Convert: B1 has a different degree and thus cannot be coverted to!");

            int i;
            GF2Polynomial[] COBMatrix;
            i = Fields.IndexOf(Basis);

            if (i == -1)
            {
                ComputeCOBMatrix(Basis);
                i = Fields.IndexOf(Basis);
            }
            COBMatrix = (GF2Polynomial[])Matrices[i];

            GF2nElement elemCopy = (GF2nElement)Elem.Clone();
            if (elemCopy is GF2nONBElement)
                ((GF2nONBElement)elemCopy).ReverseOrder();

            GF2Polynomial bs = new GF2Polynomial(DegreeN, elemCopy.ToFlexiBigInt());
            bs.ExpandN(DegreeN);
            GF2Polynomial result = new GF2Polynomial(DegreeN);
            for (i = 0; i < DegreeN; i++)
            {
                if (bs.VectorMult(COBMatrix[i]))
                    result.SetBit(DegreeN - 1 - i);
            }

            if (Basis is GF2nPolynomialField)
            {
                return new GF2nPolynomialElement((GF2nPolynomialField)Basis, result);
            }
            else if (Basis is GF2nONBField)
            {
                GF2nONBElement res = new GF2nONBElement((GF2nONBField)Basis, result.ToFlexiBigInt());
                res.ReverseOrder();

                return res;
            }
            else
            {
                throw new Exception("GF2nField.convert: B1 must be an instance of GF2nPolynomialField or GF2nONBField!");
            }
        }
Пример #5
0
        /// <summary>
        /// Sets the coefficient at <c>Index</c> to <c>Element</c>
        /// </summary>
        /// 
        /// <param name="Index">The index</param>
        /// <param name="E">The GF2nElement to store as coefficient <c>Index</c></param>
        public void Set(int Index, GF2nElement E)
        {
            if (!(E is GF2nPolynomialElement) && !(E is GF2nONBElement))
                throw new ArgumentException("GF2nPolynomial: PolynomialGF2n.Set f must be an instance of either GF2nPolynomialElement or GF2nONBElement!");

            _coeff[Index] = (GF2nElement)E.Clone();
        }
Пример #6
0
        /// <summary>
        /// Converts the given element in representation according to this field to a new element in
        /// representation according to B1 using the change-of-basis matrix calculated by computeCOBMatrix.
        /// </summary>
        ///
        /// <param name="Elem">The GF2nElement to convert</param>
        /// <param name="Basis">The basis to convert <c>Elem</c> to</param>
        ///
        /// <returns>Returns <c>Elem</c> converted to a new element representation according to <c>basis</c></returns>
        public GF2nElement Convert(GF2nElement Elem, GF2nField Basis)
        {
            if (Basis == this)
            {
                return((GF2nElement)Elem.Clone());
            }
            if (FieldPoly.Equals(Basis.FieldPoly))
            {
                return((GF2nElement)Elem.Clone());
            }
            if (DegreeN != Basis.DegreeN)
            {
                throw new Exception("GF2nField.Convert: B1 has a different degree and thus cannot be coverted to!");
            }

            int i;

            GF2Polynomial[] COBMatrix;
            i = Fields.IndexOf(Basis);

            if (i == -1)
            {
                ComputeCOBMatrix(Basis);
                i = Fields.IndexOf(Basis);
            }
            COBMatrix = (GF2Polynomial[])Matrices[i];

            GF2nElement elemCopy = (GF2nElement)Elem.Clone();

            if (elemCopy is GF2nONBElement)
            {
                ((GF2nONBElement)elemCopy).ReverseOrder();
            }

            GF2Polynomial bs = new GF2Polynomial(DegreeN, elemCopy.ToFlexiBigInt());

            bs.ExpandN(DegreeN);
            GF2Polynomial result = new GF2Polynomial(DegreeN);

            for (i = 0; i < DegreeN; i++)
            {
                if (bs.VectorMult(COBMatrix[i]))
                {
                    result.SetBit(DegreeN - 1 - i);
                }
            }

            if (Basis is GF2nPolynomialField)
            {
                return(new GF2nPolynomialElement((GF2nPolynomialField)Basis, result));
            }
            else if (Basis is GF2nONBField)
            {
                GF2nONBElement res = new GF2nONBElement((GF2nONBField)Basis, result.ToFlexiBigInt());
                res.ReverseOrder();

                return(res);
            }
            else
            {
                throw new Exception("GF2nField.convert: B1 must be an instance of GF2nPolynomialField or GF2nONBField!");
            }
        }