Beispiel #1
0
        /// <summary>
        /// Compute the product of this polynomial with an element from GF(2^m)
        /// </summary>
        ///
        /// <param name="Element">An element of the finite field GF(2^m)</param>
        ///
        /// <returns>Return <c>this * element</c> (newly created)</returns>
        public PolynomialGF2mSmallM MultWithElement(int Element)
        {
            if (!_field.IsElementOfThisField(Element))
            {
                throw new ArithmeticException("Not an element of the finite field this polynomial is defined over.");
            }

            int[] resultCoeff = MultWithElement(_coefficients, Element, _field);

            return(new PolynomialGF2mSmallM(_field, resultCoeff));
        }
        /// <summary>
        /// Creates the vector over GF(2^m) of given length and with elements from array V (beginning at the first bit)
        /// </summary>
        /// 
        /// <param name="Field">The finite field</param>
        /// <param name="V">An array with elements of vector</param>
        public GF2mVector(GF2mField Field, byte[] V)
        {
            _field = new GF2mField(Field);

            // decode vector
            int d = 8;
            int count = 1;
            while (Field.Degree > d)
            {
                count++;
                d += 8;
            }

            if ((V.Length % count) != 0)
                throw new ArgumentException("GF2mVector: Byte array is not an encoded vector over the given finite field!");

            Length = V.Length / count;
            _vector = new int[Length];
            count = 0;

            for (int i = 0; i < _vector.Length; i++)
            {
                for (int j = 0; j < d; j += 8)
                    _vector[i] |= (V[count++] & 0xff) << j;

                if (!Field.IsElementOfThisField(_vector[i]))
                    throw new ArgumentException("GF2mVector: Byte array is not an encoded vector over the given finite field!");
            }
        }
 /// <summary>
 /// Create a new vector over <c>GF(2^m)</c> of the given length and element array
 /// </summary>
 /// 
 /// <param name="Field">The finite field <c>GF(2^m)</c></param>
 /// <param name="Vector">The element array</param>
 public GF2mVector(GF2mField Field, int[] Vector)
 {
     _field = Field;
     Length = Vector.Length;
     for (int i = Vector.Length - 1; i >= 0; i--)
     {
         if (!Field.IsElementOfThisField(Vector[i]))
             throw new ArithmeticException("Element array is not specified over the given finite field.");
     }
     _vector = IntUtils.DeepCopy(Vector);
 }
Beispiel #4
0
 /// <summary>
 /// Create a new vector over <c>GF(2^m)</c> of the given length and element array
 /// </summary>
 ///
 /// <param name="Field">The finite field <c>GF(2^m)</c></param>
 /// <param name="Vector">The element array</param>
 public GF2mVector(GF2mField Field, int[] Vector)
 {
     _field = Field;
     Length = Vector.Length;
     for (int i = Vector.Length - 1; i >= 0; i--)
     {
         if (!Field.IsElementOfThisField(Vector[i]))
         {
             throw new ArithmeticException("Element array is not specified over the given finite field.");
         }
     }
     _vector = IntUtils.DeepCopy(Vector);
 }
Beispiel #5
0
        /// <summary>
        /// Creates the vector over GF(2^m) of given length and with elements from array V (beginning at the first bit)
        /// </summary>
        ///
        /// <param name="Field">The finite field</param>
        /// <param name="V">An array with elements of vector</param>
        public GF2mVector(GF2mField Field, byte[] V)
        {
            _field = new GF2mField(Field);

            // decode vector
            int d     = 8;
            int count = 1;

            while (Field.Degree > d)
            {
                count++;
                d += 8;
            }

            if ((V.Length % count) != 0)
            {
                throw new ArgumentException("GF2mVector: Byte array is not an encoded vector over the given finite field!");
            }

            Length  = V.Length / count;
            _vector = new int[Length];
            count   = 0;

            for (int i = 0; i < _vector.Length; i++)
            {
                for (int j = 0; j < d; j += 8)
                {
                    _vector[i] |= (V[count++] & 0xff) << j;
                }

                if (!Field.IsElementOfThisField(_vector[i]))
                {
                    throw new ArgumentException("GF2mVector: Byte array is not an encoded vector over the given finite field!");
                }
            }
        }