I have a binary matrix A
(only 1
and 0
), and a vector D
in Galois field (256). The vector C
is calculated as:
C = (A^^-1)*D
where A^^-1
denotes the inverse matrix of matrix A
in GF(2)
, *
is multiply operation. The result vector C
must be in GF(256)
. I tried to do it in Matlab.
A= [ 1 0 0 1 1 0 0 0 0 0 0 0 0 0;
1 1 0 0 0 1 0 0 0 0 0 0 0 0;
1 1 1 0 0 0 1 0 0 0 0 0 0 0;
0 1 1 1 0 0 0 1 0 0 0 0 0 0;
0 0 1 1 0 0 0 0 1 0 0 0 0 0;
1 1 0 1 1 0 0 1 0 1 0 0 0 0;
1 0 1 1 0 1 0 0 1 0 1 0 0 0;
1 1 1 0 0 0 1 1 1 0 0 1 0 0;
0 1 1 1 1 1 1 0 0 0 0 0 1 0;
0 0 0 0 1 1 1 1 1 0 0 0 0 1;
0 1 1 1 1 0 1 1 1 0 1 1 1 0;
0 0 0 1 0 0 0 1 0 0 0 0 0 0;
0 0 1 0 0 0 0 1 0 0 0 0 0 0;
1 1 1 1 0 0 0 0 0 0 0 0 0 0]
D=[0;0;0;0;0;0;0;0;0;0;103;198;105;115]
A=gf(A,1);
D=gf(D,8); %%2^8=256
C=inv(A)*D
%% The corrected result must be
%%C=[103;187;125;210;181;220;161;20;175;175;187;187;220;115]
However, for above code, I cannot achieved as my expected result
C=[103;187;125;210;181;220;161;20;175;175;187;187;220;115]
It produces an error as
Error using * (line 14)
Orders must match.
Could you help me achieve my expected result?
It seems there is either
A) a theoretical fault in your computation or
B) something that MATLAB doesn't support.
As per the documentation in Galois field arithmetic (emphasis mine):
And your matrices aren't.
I cant know which one is it as I have no idea how Galois fields work
The error
arises because Matlab does not support applying standard mathematical operations (
+
,*
,.*
,.^
,\
, etc.) to Galois Fields of different order,GF(2)
andGF(256)
. The inverse operation,inv(A)
is a valid operation and if you perform it on its own as shown by @Ander Biguri it will succeed and generate the inverse ofA
inGF(2)
. Your calculation breaks down when you attempt to multiplyinv(A)
andD
as the orders of these Galois Fields do not match.In this example it is unnecessary to explicitly define
A
as a Galois Field of order 2,GF(2)
as multiplication inGF(256)
takes place inGF(2)
. That is1 + 1 = 0
.If we thus modify the code that creates the Galois Field for
A
towe can then perform
which produces
C
is thus inGF(256)
and produces the expected result.