Communications Toolbox    

Arithmetic in Galois Fields

You can add, subtract, multiply, and divide elements of Galois fields using the functions gfadd, gfsub, gfmul, and gfdiv, respectively. Each of these functions has a mode for prime fields and a mode for extension fields.

Arithmetic in Prime Fields

Arithmetic in GF(p) is the same as arithmetic modulo p. The functions gfadd, gfmul, gfsub, and gfdiv accept two arguments that represent elements of GF(p) as integers between 0 and p-1. An optional third argument specifies p; if it does not appear, then the computations are performed in GF(2).

Example: Addition Table for GF(5).   The code below constructs an addition table for GF(5). If a and b are between 0 and 4, then the element gfp_add(a+1,b+1) represents the sum a+b in GF(5). For example, gfp_add(3,5) = 1 because 2+4 is 1 modulo 5.

Other values of p produce tables for different prime fields GF(p). Replacing gfadd by gfmul, gfsub, or gfdiv produces a table for the corresponding arithmetic operation in GF(p).

Arithmetic in Extension Fields

The same arithmetic functions can add elements of GF(pm) when > 1, but the format of the arguments is more complicated than in the case above. In general, arithmetic in extension fields is more complicated than arithmetic in prime fields; see the works listed in Selected Bibliography for Galois Fields for details about how the arithmetic operations work.

When working in extension fields, the functions gfadd, gfmul, gfsub, and gfdiv use the first two arguments to represent elements of GF(pm) in exponential format. The third argument, which is required, lists all elements of GF(pm) as described in the section, List of All Elements of a Galois Field. The result is in exponential format.

Example: Addition Table for GF(9).   The code below constructs an addition table for GF(32), using exponential formats relative to a root of the default primitive polynomial for GF(9). If a and b are between -1 and 7, then the element gfpm_add(a+2,b+2) represents the sum of a and b in GF(9). For example, gfpm_add(4,6) = 5 because

Using the fourth and sixth rows of the matrix field, you can verify that

Other values of p and m produce tables for different prime fields GF(pm). Replacing gfadd by gfmul, gfsub, or gfdiv produces a table for the corresponding arithmetic operation in GF(pm).


 Converting and Simplifying Element Formats Polynomials over Prime Fields