Class GF256


  • public final class GF256
    extends java.lang.Object

    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.

    Since:
    5.0.2
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private GF256​(int primitive)
      Create a representation of GF(256) using the given primitive polynomial.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      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(256).
      (package private) GF256Poly buildMonomial​(int degree, int coefficient)  
      (package private) int exp​(int a)  
      (package private) GF256Poly getOne()  
      (package private) GF256Poly getZero()  
      (package private) int inverse​(int a)  
      (package private) int log​(int a)  
      (package private) int multiply​(int a, int b)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • QR_CODE_FIELD

        public static final GF256 QR_CODE_FIELD
      • DATA_MATRIX_FIELD

        public static final GF256 DATA_MATRIX_FIELD
      • expTable

        private final int[] expTable
      • logTable

        private final int[] logTable
    • Constructor Detail

      • GF256

        private GF256​(int primitive)
        Create a representation of GF(256) 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
    • Method Detail

      • buildMonomial

        GF256Poly buildMonomial​(int degree,
                                int coefficient)
        Returns:
        the monomial representing coefficient * x^degree
      • addOrSubtract

        static int addOrSubtract​(int a,
                                 int b)
        Implements both addition and subtraction -- they are the same in GF(256).
        Returns:
        sum/difference of a and b
      • exp

        int exp​(int a)
        Returns:
        2 to the power of a in GF(256)
      • log

        int log​(int a)
        Returns:
        base 2 log of a in GF(256)
      • inverse

        int inverse​(int a)
        Returns:
        multiplicative inverse of a
      • multiply

        int multiply​(int a,
                     int b)
        Parameters:
        a -
        b -
        Returns:
        product of a and b in GF(256)