DES加密功能给我一个错误的密文 [英] DES encryption function give me a cipher text that is wrong

查看:67
本文介绍了DES加密功能给我一个错误的密文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经用haskell编写了DES算法,但是当我尝试使用它时,它不能给出正确的输出,我已经对每个函数进行了单独的测试,它们似乎可以正常工作,我接受了一条加密消息:plainText = 123456ABCD132536,密钥= AABB09182736CCDD,用DES加密时,它假定给我作为输出cipherText = C0B7A8D05F3A829C.子项都是(K1..K16)正确的,l0,r0也是正确的,l1,r1,l2,r2也是正确的,但是在第3轮,我得到r3 = B00A9591,但是根据a,它应该是B8089591.我遵循的教程.

I have written the DES algorithm in haskell, but when i tried it, it doesn't give the correct output, i have tested every function on its own, they seem to work correctly, i have taken a message to encrypt: plainText = 123456ABCD132536 with the key = AABB09182736CCDD, when encrypted with DES it suppose to give me as output cipherText = C0B7A8D05F3A829C. The subkeys are all (K1..K16) correct, l0, r0 are correct as well , so are l1, r1 , l2, r2 , but at round 3 , i get r3 = B00A9591 , but its supposed to be B8089591 according to a tutorial that i follow.

(我们有r2 = 4A1210F6,展开后变成2540A40A17AC,在用子项k3 = 6EDA4ACF5B5进行XOR后,我们得到23AD00A6E219,在替换后得到232713FA,在直接置换后得到EA727605,最后得到l2 = xor5A78E394我们得到B00A9591)

(we have r2 = 4A1210F6, after expansion it becomes 2540A40A17AC, after the XOR with the subkey k3 = 6EDA4ACF5B5 we get 23AD00A6E219, after substitution we get 232713FA , after the straight permutation we get EA727605, and finaly an xor with l2 = 5A78E394 we get B00A9591)

在哪一点是不正确的?即使我手工完成也得到相同的结果,但我不明白问题出在哪里,因为第三轮使用的功能与第一轮和第二轮使用的功能相同,没有任何作用问题.有人可以给我正确的r3值,以及对可能存在问题的任何想法吗?这花了我很长时间.谢谢.

At which point is it incorrect?even if i do it by hand i get the same results, i didn't understand what the problem is because the functions used at round 3 are the same used at round 1 and 2 without any problem. Can someone give me the correct value of r3, and any ideas of what could be the problem?it took me a very long time. Thank you.

推荐答案

这是从Eugene Styer的

This is done from a copy of Eugene Styer's JavaScript DES Example that has been modified to allow the key to be entered by removing the read-only attributes and default values. A copy of the original code allowing the key to be set used to be available on Google Code.

它产生输出密文c0b7a8d05f3a829c

It produces the output ciphertext c0b7a8d05f3a829c

Round 3  
E   :  001001 010100 000010 100100 000010 100001 011110 101100 2540A40A17AC  
KS  :  000001 101110 110110 100100 101011 001111 010110 110101 06EDA4ACF5B5  
E xor KS:  001000 111010 110100 000000 101001 101110 001000 011001 23AD00A6E219  
Sbox:  0010 0011 0010 0111 0001 0011 1111 0000 232713FA  (should be 232713F0)  
P   : 11100010 01110000 01110110 00000101 EA727605 (should be E2707605)  
L[i]: 01001010 00010010 00010000 11110110  
R[i]: 10111000 00001000 10010101 10010001  

您的十六进制输出已带有注释,并告诉我们S框8的第01行索引12(1100)当其应为0000时将产生1010的输出.

Your outputs in hexidecimal have been annotated and tell us row 01 index 12 (1100) of S Box 8 is producing an output of 1010 when it should be 0000.

来自FIPS Pub 46的S Box 8值:

S Box 8 values from FIPS Pub 46:

    13, 2, 8, 4, 6,15,11, 1,10, 9, 3,14, 5, 0,12, 7,
     1,15,13, 8,10, 3, 7, 4,12, 5, 6,11, 0,14, 9, 2,
     7,11, 4, 1, 9,12,14, 2, 0, 6,10,13,15, 3, 5, 8,
     2, 1,14, 7, 4,10, 8,13,15,12, 9, 0, 3, 5, 6,11,

第二行向下,第13列元素.

The second row down, the 13th column element.

对于标记为B1至B6的6位输入011001,通过将B1和B6(01或从0开始计数的第1行)级联来找到行,通过将B2至B5(1100)进行级联来找到该列.

For a 6 bit input 011001 labelled B1 through B6, The row is found by concatenating B1 and B6 (01 or row 1 counting from 0), the column by concatenating B2 through B5 (1100).

后面的P排列的差异是由两个意外的"1"位引起的.

The difference in the following P permutation is accounted for by the two unexpected '1' bits.

没有完整且可验证的最小示例" ,就无法确定这是否是唯一错误.

Without a Minimal Complete and Verifiable example it's not possible to determine if that is the sole error.

请参见 vhdl-数据加密标准测试向量-堆栈溢出有关允许的测试向量的信息,请使用包含全零的键测试S Box.(答案最后一段中的保管箱链接仍然有效.)

See vhdl - Data Encryption Standard test vectors - Stack Overflow for information on test vectors that allow among other things, testing S Boxes with a key comprised of all zeros. (The dropbox link in the last paragraph of the answer is still valid.)

差异显示了对JS-DES.html的修改:

The diff showing the modifications to JS-DES.html:

623c623
<         <td><input name="key" value="0000000000000000" size="25" type="text"></td>
---
>         <td><input name="key" value="3b3898371520f75e" readonly="readonly" size="25" type="text"></td>
627c627
<         <td><input name="keyb" value="0000000000000000" size="25" type="text"></td>
---
>         <td><input name="keyb" value="922fb510c71f436e" readonly="readonly" size="25" type="text"></td>

这篇关于DES加密功能给我一个错误的密文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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