java.lang.Object
com.google.zxing.common.reedsolomon.GenericGF

public final class GenericGFextends Object

This class contains utility methods for performing mathematical operations over the Galois Fields. Operations use a given primitive polynomial in calculations.

Throughout this package, elements of the GF are represented as an int for convenience and speed (but at the cost of memory).

  • Field Summary

    Modifier and Type
    Field
    Description
    static final GenericGF
    Galois field for Aztec 10-bit data symbols (1024 elements).
    static final GenericGF
    Galois field for Aztec 12-bit data symbols (4096 elements).
    static final GenericGF
    Galois field for Aztec 6-bit data symbols (64 elements).
    static final GenericGF
    Alias for DATA_MATRIX_FIELD_256.
    static final GenericGF
    Galois field for Aztec parameter symbols (16 elements).
    static final GenericGF
    Galois field for Data Matrix symbols (256 elements).
    private final int[]
    Exponent lookup table for the field.
    private final int
    Base of the generator used to build polynomials.
    private final int[]
    Logarithm lookup table for the field.
    static final GenericGF
    Alias for AZTEC_DATA_6.
    private final GenericGFPoly
    The one polynomial of this field.
    private final int
    The primitive polynomial defining the field.
    static final GenericGF
    Galois field for QR Code symbols (256 elements).
    private final int
    Number of elements in the field.
    private final GenericGFPoly
    The zero polynomial of this field.
  • Constructor Summary

    Constructors
    Constructor
    Description
    GenericGF(int primitive, int size, int b)
    Create a representation of GF(size) using the given primitive polynomial.
  • Method Summary

    Modifier and Type
    Method
    Description
    (package private) static int
    addOrSubtract(int a, int b)
    Implements both addition and subtraction -- they are the same in GF(size).
    (package private) GenericGFPoly
    buildMonomial(int degree, int coefficient)
    Build the monomial coefficient * x^degree.
    (package private) int
    exp(int a)
    Get a field element's antilog.
    int
    Get the integer the Reed-Solomon generator polynomial is built over.
    (package private) GenericGFPoly
    Get the multiplicative identity of this field.
    int
    Get the field's cardinality.
    (package private) GenericGFPoly
    Get the additive identity of this field.
    (package private) int
    inverse(int a)
    Get the multiplicative inverse of a field element.
    (package private) int
    log(int a)
    Get a field element's log.
    (package private) int
    multiply(int a, int b)
    Multiply two field elements.
    Human-readable string representation of this Galois field.

    Methods inherited from class Object

    clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • AZTEC_DATA_12

      public static final GenericGF AZTEC_DATA_12
      Galois field for Aztec 12-bit data symbols (4096 elements).
    • AZTEC_DATA_10

      public static final GenericGF AZTEC_DATA_10
      Galois field for Aztec 10-bit data symbols (1024 elements).
    • AZTEC_DATA_6

      public static final GenericGF AZTEC_DATA_6
      Galois field for Aztec 6-bit data symbols (64 elements).
    • AZTEC_PARAM

      public static final GenericGF AZTEC_PARAM
      Galois field for Aztec parameter symbols (16 elements).
    • QR_CODE_FIELD_256

      public static final GenericGF QR_CODE_FIELD_256
      Galois field for QR Code symbols (256 elements).
    • DATA_MATRIX_FIELD_256

      public static final GenericGF DATA_MATRIX_FIELD_256
      Galois field for Data Matrix symbols (256 elements).
    • AZTEC_DATA_8

      public static final GenericGF AZTEC_DATA_8
      Alias for DATA_MATRIX_FIELD_256.
    • MAXICODE_FIELD_64

      public static final GenericGF MAXICODE_FIELD_64
      Alias for AZTEC_DATA_6.
    • expTable

      private final int[] expTable
      Exponent lookup table for the field.
    • logTable

      private final int[] logTable
      Logarithm lookup table for the field.
    • zero

      private final GenericGFPoly zero
      The zero polynomial of this field.
    • one

      private final GenericGFPoly one
      The one polynomial of this field.
    • size

      private final int size
      Number of elements in the field.
    • primitive

      private final int primitive
      The primitive polynomial defining the field.
    • generatorBase

      private final int generatorBase
      Base of the generator used to build polynomials.
  • Constructor Details

    • GenericGF

      public GenericGF(int primitive, int size, int b)
      Create a representation of GF(size) using the given primitive polynomial.
      Parameters:
      primitive - irreducible polynomial whose coefficients are represented by the bits of an int, where the least-significant bit represents the constant coefficient
      size - the number of elements in the field, a power of two
      b - 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.
  • Method Details

    • getZero

      GenericGFPoly getZero()
      Get the additive identity of this field.
      Returns:
      the zero polynomial, the additive identity in GF(size)
    • getOne

      GenericGFPoly getOne()
      Get the multiplicative identity of this field.
      Returns:
      the one polynomial, the multiplicative identity in GF(size)
    • buildMonomial

      GenericGFPoly buildMonomial(int degree, int coefficient)
      Build the monomial coefficient * x^degree.
      Parameters:
      degree - the exponent of x, not negative
      coefficient - the leading coefficient, whose field value is in [0, size)
      Returns:
      the monomial, or the zero polynomial if coefficient is 0
      Throws:
      IllegalArgumentException - if degree is negative
    • addOrSubtract

      static int addOrSubtract(int a, int b)
      Implements both addition and subtraction -- they are the same in GF(size).
      Parameters:
      a - the first operand, whose field value is in [0, size)
      b - the second operand, whose field value is in [0, size)
      Returns:
      sum/difference of a and b
    • exp

      int exp(int a)
      Get a field element's antilog.
      Parameters:
      a - the exponent, in [0, size)
      Returns:
      2 to the power of a in GF(size)
    • log

      int log(int a)
      Get a field element's log.
      Parameters:
      a - a nonzero field value in [1, size)
      Returns:
      base 2 log of a in GF(size)
      Throws:
      IllegalArgumentException - if a is 0, whose log is undefined
    • inverse

      int inverse(int a)
      Get the multiplicative inverse of a field element.
      Parameters:
      a - a nonzero field value in [1, size)
      Returns:
      multiplicative inverse of a, that is a such that a * result is 1
      Throws:
      ArithmeticException - if a is 0, which has no inverse
    • multiply

      int multiply(int a, int b)
      Multiply two field elements.
      Parameters:
      a - the first factor, whose field value is in [0, size)
      b - the second factor, whose field value is in [0, size)
      Returns:
      product of a and b in GF(size), 0 if either factor is 0
    • getSize

      public int getSize()
      Get the field's cardinality.
      Returns:
      the number of elements in this field
    • getGeneratorBase

      public int getGeneratorBase()
      Get the integer the Reed-Solomon generator polynomial is built over.
      Returns:
      the generator base
    • toString

      public String toString()
      Human-readable string representation of this Galois field.
      Overrides:
      toString in class Object