public bool Decode(int[] received, int twoS)
        {
            var poly = new GenericGfPoly(field, received);
            var syndromeCoefficients = new int[twoS];
            var noError = true;

            for (var i = 0; i < twoS; i++)
            {
                var eval = poly.EvaluateAt(field.Exp(i + field.GeneratorBase));
                syndromeCoefficients[syndromeCoefficients.Length - 1 - i] = eval;
                if (eval != 0)
                {
                    noError = false;
                }
            }
            if (noError)
            {
                return(true);
            }
            var syndrome = new GenericGfPoly(field, syndromeCoefficients);

            var sigmaOmega = RunEuclideanAlgorithm(field.BuildMonomial(twoS, 1), syndrome, twoS);

            if (sigmaOmega == null)
            {
                return(false);
            }

            var sigma          = sigmaOmega[0];
            var errorLocations = FindErrorLocations(sigma);

            if (errorLocations == null)
            {
                return(false);
            }

            var omega           = sigmaOmega[1];
            var errorMagnitudes = FindErrorMagnitudes(omega, errorLocations);

            for (var i = 0; i < errorLocations.Length; i++)
            {
                var position = received.Length - 1 - field.Log(errorLocations[i]);
                if (position < 0)
                {
                    return(false);
                }
                received[position] = GenericGf.AddOrSubtract(received[position], errorMagnitudes[i]);
            }

            return(true);
        }
 public ReedSolomonDecoder(GenericGf field)
 {
     this.field = field;
 }