File Exchange

image thumbnail

A toolbox for simple finite field operation

version (10.9 KB) by Samuel Cheng
This is a toolbox providing simple operations (+,-,*,/,.*,./,inv) for finite field.


Updated 04 Sep 2012

View License

This toolbox can handle simple operations (+,-,*,/,.*,./,inv) of GF(p^n) for any p and n. Examples are given below (also documented in gf_test.m).

If you find any bug or have any concern/comment, please contact me.

% setup path
% create gf class of 3^2

% Eg. 1
a=[2 1;1 0]

% compute rank

% compute inverse
inva = gf9.inv(a)

% Check inverse

% matrix divide

% Eg. 2
b=[1 2 1;1 0 1];
c=[1 1 0;2 1 1];

% compute summation

% compute subtraction

% compute dot multiplication

% compute dot division

% output the primitive polynomial
gf9.return_primitive_polynomial % x^2 + 1

% show polynomial representation
gf9.return_poly_representation(5) % x + 2

% Eg. 3

% manipulating polynomials.

a=[1 2 1 1];
b=[1 3 1];



Cite As

Samuel Cheng (2020). A toolbox for simple finite field operation (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (4)

Andrei Dzis


when i try run the code there are problem in rank function
and what is mean obj

Samuel Cheng

@Valentina's comments, I have added functions for multiplying and dividing polynomials.


Hi Samuel,
I'm trying to use this code to perform some AES operations... What I need is e.g. to define a polynomial which can have a max degree = 7, with coefficients 0 and 1. (i.e., over GF(2)), and then compute its inverse modulo a poly of degree 8, again with binay coeffs. I can't figure out how to declare the gf, which in your example is gf9=gf(3,2); and then how do i define the poly? what does the 2 line matrix in your example mean, a=[2 1;1 0]?


Added new functionality to manipulate polynomials.

Oops, found two silly bugs. First, an error check condition was corrected.

Second, I guess it is probably the safest to run a separate script to setup path and so I extracted that part out.

MATLAB Release Compatibility
Created with R2010b
Compatible with any release
Platform Compatibility
Windows macOS Linux