📄 gfdiv.m
字号:
function q = gfdiv(b, a, p)
%GFDIV Element-by-element division in GF(P) or GF(P^M).
% Q = GFDIV(B, A) divides B by A resulting in the quotient Q in GF(2).
% A zero element in A will result in an NaN solution.
%
% Q = GFDIV(B, A, P) divides B by A resulting in the quotient Q in
% GF(P), where P must be a prime number. When P is a list of all the
% elements in GF(P^M), and P is a prime number, Q is the result of the
% dividing operation in the GF(P^M) field.
%
% See also GFADD, GFMUL, GFTUPLE, GFPRETTY
% Wes Wang 6/8/94, 7/19/94, 10/7/95
% Copyright (c) 1995-96 by The MathWorks, Inc.
% $Revision: 1.1 $ $Date: 1996/04/01 17:58:35 $
if nargin < 2
error('Not enough input for GFADD')
elseif nargin < 3
p = 2;
end
a = a(:);
b = b(:);
if length(p) <= 1
if ~isempty([find(a~=floor(a)), find(a<0), find(a>=p)])
error('The polynomial coeficients must be in GF(P)')
elseif ~isempty([find(b~=floor(b)), find(b<0), find(b>=p)])
error('The polynomial coeficients must be in GF(P)')
end;
len_a = length(a);
len_b = length(b);
x = a;
if p > 2
x = a .^ (p-2);
if floor(x) ~= x
disp('Warning: The prime number is too big to be handled by gfdiv');
end;
end;
indx = find(~(x > 0));
if (len_a == len_b) | (len_b == 1)
q = rem(b .* x, p);
q(indx) = indx + NaN;
elseif len_a == 1
if isempty(indx)
q = rem(b .* x, p);
else
q = b + NaN;
end;
elseif len_a > len_b
x = a(1:len_b);
indx = find(~(x > 0));
q = rem(b .* x, p);
q(indx) = indx + NaN;
else
q = b;
q(1:len_a) = rem(b(1:len_a) .* x, p);
q(indx) = indx + NaN;
end;
else
% GF(P^M) field computation.
prim = max(max(p)) + 1;
[n_p, m_p] = size(p);
indxa = find(~(a>=0));
indxb = find(~(b >=0));
len_a = length(a);
len_b = length(b);
if (len_a == len_b) | (len_a == 1) | (len_b == 1)
q = rem(b + n_p - 1 - a, n_p - 1);
else
cal_len = min(len_a, len_b);
q = rem(b(1 : cal_len) + n_p - 1 - a(1 : cal_len), n_p - 1);
end;
q(indxb) = indxb - Inf;
q(indxa) = indxa + NaN;
end;
q=q(:);
%--end of GFDIV--
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -