1 ## Copyright (C) 2002 David Bateman
3 ## This program is free software; you can redistribute it and/or modify it under
4 ## the terms of the GNU General Public License as published by the Free Software
5 ## Foundation; either version 3 of the License, or (at your option) any later
8 ## This program is distributed in the hope that it will be useful, but WITHOUT
9 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 ## You should have received a copy of the GNU General Public License along with
14 ## this program; if not, see <http://www.gnu.org/licenses/>.
17 ## @deftypefn {Function File} {} minpol (@var{v})
19 ## Finds the minimum polynomial for elements of a Galois Field. For a
20 ## vector @var{v} with @math{N} components, representing @math{N} values
21 ## in a Galois Field GF(2^@var{m}), return the minimum polynomial in GF(2)
22 ## representing thos values.
25 function r = minpol (v)
28 error("usage: r = minpol(v)");
32 error("minpol: argument must be a galois variable");
35 if (min (size (v)) > 1 || nargin != 1)
36 usage ("minpol (v), where v is a galois vector");
41 prim_poly = v.prim_poly;
44 ## Find cosets of GF(2^m) and convert from cell array to matrix
45 cyclocoset = cosets(m, prim_poly);
46 cyclomat = zeros(max(size(cyclocoset)),m);
47 for j=1:max(size(cyclocoset))
48 cyclomat(j,1:length(cyclocoset{j})) = cyclocoset{j};
56 ## Find the coset within which the current element falls
57 [rc, ignored] = find(cyclomat == v(j));
61 ## Create the minimum polynomial from its roots
62 ptmp = gf([1,rv(1)], m, prim_poly);
64 ptmp = conv(ptmp, [1,rv(i)]);
67 ## Need to left-shift polynomial to divide by x while can
72 ptmp = [zeros(1,i), ptmp(1:m+1-i)];
77 ## Ok, now put the return value into GF(2)