在Matlab中如何在GF(2)中执行逆运算并在GF(256)中进行乘法运算? [英] How to perform inverse in GF(2) and multiply in GF(256) in Matlab?

查看:621
本文介绍了在Matlab中如何在GF(2)中执行逆运算并在GF(256)中进行乘法运算?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Galois字段(256)中有一个二进制矩阵A(仅10)和向量D.向量C的计算公式为:

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

其中,A^^-1表示GF(2)中矩阵A的逆矩阵,*是乘法运算.结果向量C必须在GF(256)中.我试图在Matlab中做到这一点.

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]

它产生错误为

Error using  *  (line 14)
Orders must match.

您能帮助我达到预期的结果吗?

Could you help me achieve my expected result?

推荐答案

错误

使用*时出错(第14行)
订单必须匹配.

Error using * (line 14)
Orders must match.

会发生变化,因为Matlab不支持将标准数学运算(+*.*.^\等)应用于不同顺序的GF(2).反向运算inv(A)是有效的运算,如果您以 Ander Biguri 将成功并在GF(2)中生成A的逆.当您尝试将inv(A)D相乘时,由于这些Galois字段的顺序不匹配,计算会中断.

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.

在此示例中,没有必要将A显式定义为2的Galois字段,因为GF(256)中的乘法发生在GF(2)中.那是1 + 1 = 0.

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.

如果我们因此将为A创建Galois字段的代码修改为

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

A = gf(A, 8);

然后我们可以执行

C = inv(A)*D

产生

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

因此,

CGF(256)中,并产生预期的结果.

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

这篇关于在Matlab中如何在GF(2)中执行逆运算并在GF(256)中进行乘法运算?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆