GenericGF constructor

GenericGF(
  1. int _primitive,
  2. int _size,
  3. int _generatorBase
)

Create a representation of GF(size) using the given primitive polynomial.

_primitive irreducible polynomial whose coefficients are represented by the bits of an int, where the least-significant bit represents the constant coefficient _size the size of the field _generatorBase the factor b in the generator polynomial can be 0- or 1-based (g(x) = (x+a^b)(x+a^(b+1))...(x+a^(b+2t-1))). In most cases it should be 1, but for QR code it is 0.

Implementation

GenericGF(this._primitive, this._size, this._generatorBase) {
  _expTable = Int32List(_size);
  _logTable = Int32List(_size);
  int x = 1;
  for (int i = 0; i < _size; i++) {
    _expTable[i] = x;
    x *= 2; // 2 (the polynomial x) is a primitive element
    if (x >= _size) {
      x ^= _primitive;
      x &= _size - 1;
    }
  }
  for (int i = 0; i < _size - 1; i++) {
    _logTable[_expTable[i]] = i;
  }
  // logTable[0] == 0 but this should never be used
  _zero = GenericGFPoly(this, Int32List.fromList([0]));
  _one = GenericGFPoly(this, Int32List.fromList([1]));
}