mceliece加密算法c语言,McEliece加密/解密算法

我正在尝试编写McEliece密码系统,但是我在将算法的解密步骤中的二进制向量和linsolve部分合并时遇到了问题。McEliece加密/解密算法

我期待阵列m等于解密后消息数组x,但我得到错误的结果:

x =

1 1 1 1

ciphertext =

1 1 1 1 0 1 1

m =

1.2500 0.5000 0.5000 0.7500

为什么我的解密结果从我的纯文本消息不同?

这是我到目前为止有:对McEliece公钥体制密码

clc;clear all;

n = 7;

k = 4; %Let C be an (n,k)-linear code

g = [ 1 0 0 0 1 1 0

0 1 0 0 1 0 1

0 0 1 0 0 1 1

0 0 0 1 1 1 1]; %Let G be a generator matrix for C.

s = [ 1 1 0 1

1 0 0 1

0 1 1 1

1 1 0 0]; %Alice selects a random (k x k) binary non-singular matrix S

p = [ 0 1 0 0 0 0 0

0 0 0 1 0 0 0

0 0 0 0 0 0 1

1 0 0 0 0 0 0

0 0 1 0 0 0 0

0 0 0 0 0 1 0

0 0 0 0 1 0 0]; %Alice selects a random (n x n) permutation matrix P.

% s , g and p is private key (alice has a private key)

% g'=s*g*p is public key (alice compute the public key and send to Bob)

gg = s*g*p; %Alice computes the (n x k)matrix g'=s*g*p .

key = mod(gg,2); % public key

x = [ 1 1 1 1 ] %message

t = 1;

e = [ 0 0 0 0 1 0 0 ]; % the erorr

%%the Encryption ((Bob Encrypt the message x by using the public key))

y = x*key;

y1=mod(y,2);

ciphertext=mod((y+e),2) % ciphertext is Encrypt the message x (send the ciphertext to Alice)

%%the Decryption ((alice decrypt the ciphertext , the result must equal to the orginal message x (by using the private key)))

yy = ciphertext*inv(p);

ee = e*inv(p);

xsg = mod((yy-ee),2);

xs = linsolve(g',xsg');

m = mod((xs' * inv(s)),2) % m must equal to x .

更多细节可以在这里找到:

我试图实现这个例子在上面的链接给出:

例如,我们将使用(7,4)汉明码corr影响所有 单个错误。对于这个码的生成矩阵由下式给出(注意 聪明的选择):

G = [1 0 0 0 1 1 0

0 1 0 0 1 0 1

0 0 1 0 0 1 1

0 0 0 1 1 1 1];

和Bob选择的扰频器矩阵

S = [1 1 0 1

1 0 0 1

0 1 1 1

1 1 0 0];

和置换矩阵

P = [0 1 0 0 0 0 0

0 0 0 1 0 0 0

0 0 0 0 0 0 1

1 0 0 0 0 0 0

0 0 1 0 0 0 0

0 0 0 0 0 1 0

0 0 0 0 1 0 0];

鲍勃使得公开发电机矩阵

G' = SGP = [1 1 1 1 0 0 0

1 1 0 0 1 0 0

1 0 0 1 1 0 1

0 1 0 1 1 1 0];

如果Alice希望将消息发送x = (1 1 0 1)给Bob,她第一 构造一个权重1的误差矢量,说e = (0 0 0 0 1 0 0)和 计算

y = xG' + e

= (0 1 1 0 0 1 0) + (0 0 0 0 1 0 0)

= (0 1 1 0 1 1 0)

她然后发送给Bob。

在接收y,鲍勃首先计算y' = yP^-1,其中

P^-1 = [0 0 0 1 0 0 0

1 0 0 0 0 0 0

0 0 0 0 1 0 0

0 1 0 0 0 0 0

0 0 0 0 0 0 1

0 0 0 0 0 1 0

0 0 1 0 0 0 0];

获得y' = (1 0 0 0 1 1 1)。现在Bob用快速的 解码算法解码y'(在这个例子中是Hamming解码)。 y'的征状是(1 1 1 0)T,所以错误发生在位置7(细节 省略)。鲍勃现在拥有代码字y'' = (1 0 0 0 1 1 0)。因为聪明的选择 为G,Bob知道xS = (1 0 0 0),他 现在可以通过矩阵

S-1 = [1 1 0 1

1 1 0 0

0 1 1 1

1 0 0 1];

获得

x = (1 0 0 0)S^-1 = (1 1 0 1).

+0

它并没有让你的代码和例子更清晰,没有匹配的值,并且你已经交换了Bob和Alice!你也没有说过具体哪里出了问题? –

+0

你的问题是什么?请阅读[this](http://stackoverflow.com/help/how-to-ask)。 –

+0

解密不工作即时通讯使用linsolve但它不适用于矩形矩阵 –

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值