Reputation: 103
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.
(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)
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.
Upvotes: 1
Views: 571
Reputation:
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.
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
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.
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,
The second row down, the 13th column element.
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).
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.
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.)
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>
Upvotes: 1