Example #1
0
        /// <summary>
        /// Multiply current Polynomial to anotherone.
        /// </summary>
        /// <returns>Result polynomial after multiply</returns>
        internal Polynomial Multiply(Polynomial other)
        {
            if (Primitive != other.Primitive)
            {
                throw new ArgumentException("Polynomial cannot perform Multiply as they do not have same Primitive for GaloisField256");
            }
            if (IsMonomialZero || other.IsMonomialZero)
            {
                return(new Polynomial(GField, new int[] { 0 }));
            }

            int[] aCoefficients = Coefficients;
            int   aLength       = aCoefficients.Length;

            int[] bCoefficient = other.Coefficients;
            int   bLength      = bCoefficient.Length;

            int[] rCoefficients = new int[aLength + bLength - 1];

            for (int aIndex = 0; aIndex < aLength; aIndex++)
            {
                int aCoeff = aCoefficients[aIndex];
                for (int bIndex = 0; bIndex < bLength; bIndex++)
                {
                    rCoefficients[aIndex + bIndex] =
                        GField.Addition(rCoefficients[aIndex + bIndex], GField.Product(aCoeff, bCoefficient[bIndex]));
                }
            }
            return(new Polynomial(GField, rCoefficients));
        }
Example #2
0
        internal Polynomial CoefficientXor(int[] smallerCoefficients, int[] largerCoefficients)
        {
            if (smallerCoefficients.Length > largerCoefficients.Length)
            {
                throw new ArgumentException("Can not perform CoefficientXor method as smaller Coefficients length is larger than larger one.");
            }
            int targetLength = largerCoefficients.Length;

            int[] xorCoefficient = new int[targetLength];
            int   lengthDiff     = largerCoefficients.Length - smallerCoefficients.Length;

            Array.Copy(largerCoefficients, 0, xorCoefficient, 0, lengthDiff);

            for (int index = lengthDiff; index < targetLength; index++)
            {
                xorCoefficient[index] = GField.Addition(largerCoefficients[index], smallerCoefficients[index - lengthDiff]);
            }

            return(new Polynomial(GField, xorCoefficient));
        }