This class contains utility methods for performing mathematical operations over the Galois Field GF(256). Operations use a given primitive polynomial in calculations.

Throughout this package, elements of GF(256) are represented as an int for convenience and speed (but at the cost of memory). Only the bottom 8 bits are really used.

Example #1
0
 /// <param name="field">the {@link GF256} instance representing the field to use
 /// to perform computations
 /// </param>
 /// <param name="coefficients">coefficients as ints representing elements of GF(256), arranged
 /// from most significant (highest-power term) coefficient to least significant
 /// </param>
 /// <throws>  IllegalArgumentException if argument is null or empty, </throws>
 /// <summary> or if leading coefficient is 0 and this is not a
 /// constant polynomial (that is, it is not the monomial "0")
 /// </summary>
 internal GF256Poly(GF256 field, int[] coefficients)
 {
     if (coefficients == null || coefficients.Length == 0)
     {
         throw new ArgumentException();
     }
     this.field = field;
     int coefficientsLength = coefficients.Length;
     if (coefficientsLength > 1 && coefficients[0] == 0)
     {
         // Leading term must be non-zero for anything except the constant polynomial "0"
         int firstNonZero = 1;
         while (firstNonZero < coefficientsLength && coefficients[firstNonZero] == 0)
         {
             firstNonZero++;
         }
         if (firstNonZero == coefficientsLength)
         {
             this.coefficients = field.Zero.coefficients;
         }
         else
         {
             this.coefficients = new int[coefficientsLength - firstNonZero];
             Array.Copy(coefficients, firstNonZero, this.coefficients, 0, this.coefficients.Length);
         }
     }
     else
     {
         this.coefficients = coefficients;
     }
 }
 public ReedSolomonEncoder(GF256 field)
 {
     if (!GF256.QR_CODE_FIELD.Equals(field))
     {
         throw new ArgumentException("Only QR Code is supported at this time");
     }
     this.field = field;
     cachedGenerators = new List<GF256Poly>(10);
     cachedGenerators.Add(new GF256Poly(field, new[] {1}));
 }