How to perform inverse in GF(2) and multiply in GF(256) in Matlab?

Deadly 提交于 2019-12-02 07:58:54

问题


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?


回答1:


The error

Error using * (line 14)
Orders must match.

arises because Matlab does not support applying standard mathematical operations (+, *, .*, .^, \, etc.) to Galois Fields of different order, GF(2) and GF(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 of A in GF(2). Your calculation breaks down when you attempt to multiply inv(A) and D 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 in GF(256) takes place in GF(2). That is 1 + 1 = 0.

If we thus modify the code that creates the Galois Field for A to

A = gf(A, 8);

we can then perform

C = inv(A)*D

which produces

C = GF(2^8) array. Primitive polynomial = D^8+D^4+D^3+D^2+1 (285 decimal)

Array elements = 

         103
         187
         125
         210
         181
         220
         161
          20
         175
         175
         187
         187
         220
         115

C is thus in GF(256) and produces the expected result.




回答2:


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):

Section Overview. You can perform arithmetic operations on Galois arrays by using familiar MATLAB operators, listed in the table below. Whenever you operate on a pair of Galois arrays, both arrays must be in the same Galois field.

And your matrices aren't.

I cant know which one is it as I have no idea how Galois fields work



来源:https://stackoverflow.com/questions/33527625/how-to-perform-inverse-in-gf2-and-multiply-in-gf256-in-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!