static GF2pPolynomial CalculateSyndromes(GF2pPolynomial message, int eccLength)
 {
     int[] syndromes = new int[eccLength]; // add a zero at the front to simply later calculations
     for (int i = 0; i < syndromes.Length; i++)
     {
         syndromes[i] = message.Evaluate(message.Field.Exp(i + 1));                           // add 1 because we assume fcr == 1
     }
     return(new GF2pPolynomial(message.Field, syndromes, false));
 }
 static int[] Forney(GF2pPolynomial evaluator, int[] errorPositions, int startIndex)
 {
     int[] powers = new int[errorPositions.Length], magnitudes = new int[powers.Length - startIndex];
     for (int i = 0; i < powers.Length; i++)
     {
         powers[i] = evaluator.Field.Exp(errorPositions[i]);
     }
     for (int i = 0; i < magnitudes.Length; i++)
     {
         int invPower = evaluator.Field.Invert(powers[i + startIndex]), divisor = 1;
         for (int ei = 0; ei < powers.Length; ei++)
         {
             if (ei != i + startIndex)
             {
                 divisor = evaluator.Field.Multiply(divisor, evaluator.Field.Multiply(powers[ei], invPower) ^ 1);
             }
         }
         magnitudes[i] = evaluator.Field.Divide(evaluator.Evaluate(invPower), divisor);
     }
     return(magnitudes);
 }
        static int[] FindErrors(GF2pPolynomial locator, int dataLength)
        { // TODO: ideally we'd use the more efficient Chien's search here rather than this brute-force approach
            int[] errorPositions = new int[locator.Degree];
            int   ei             = 0;

            for (int maxValue = (int)(locator.Field.Order - 1), di = 0; di < dataLength; di++)
            {
                if (locator.Evaluate(locator.Field.Exp(maxValue - di)) == 0)
                {
                    if (ei != errorPositions.Length)
                    {
                        errorPositions[ei++] = di;
                    }
                    else
                    {
                        return(null);
                    }
                }
            }

            return(ei == errorPositions.Length ? errorPositions : null);
        }