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

喜夏-厌秋 提交于 2019-12-02 02:55:01

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.

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

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