Esempio n. 1
0
        // Method added by Sonic-The-Hedgehog-LNK1123 (github.com/Sonic-The-Hedgehog-LNK1123)
        internal GenericGFPoly calculateForneySyndromes(GenericGFPoly syndromes, int[] positions, int messageLength)
        {
            int[] positionsReversed = new int[positions.Length];

            for (int i = 0; i < positions.Length; i++)
            {
                positionsReversed[i] = messageLength - 1 - positions[i];
            }

            int forneySyndromesLength = syndromes.Coefficients.Length;

            int[] syndromeCoefficients = new int[syndromes.Coefficients.Length];
            Array.Copy(syndromes.Coefficients, 0, syndromeCoefficients, 0, syndromes.Coefficients.Length);

            GenericGFPoly forneySyndromes = new GenericGFPoly(field, syndromeCoefficients, false);

            for (int i = 0; i < positions.Length; i++)
            {
                int x = field.exp(positionsReversed[i]);
                for (int j = 0; j < forneySyndromes.Coefficients.Length - 1; j++)
                {
                    forneySyndromes.Coefficients[forneySyndromesLength - j - 1] = GenericGF.addOrSubtract(field.multiply(forneySyndromes.getCoefficient(j), x), forneySyndromes.getCoefficient(j + 1));
                }
            }

            return(forneySyndromes);
        }
Esempio n. 2
0
        /// <summary>
        /// evaluation of this polynomial at a given point
        /// </summary>
        /// <param name="a">A.</param>
        /// <returns>evaluation of this polynomial at a given point</returns>
        internal int evaluateAt(int a)
        {
            int result = 0;

            if (a == 0)
            {
                // Just return the x^0 coefficient
                return(getCoefficient(0));
            }
            int size = coefficients.Length;

            if (a == 1)
            {
                // Just the sum of the coefficients
                foreach (var coefficient in coefficients)
                {
                    result = GenericGF.addOrSubtract(result, coefficient);
                }
                return(result);
            }
            result = coefficients[0];
            for (int i = 1; i < size; i++)
            {
                result = GenericGF.addOrSubtract(field.multiply(a, result), coefficients[i]);
            }
            return(result);
        }