1 // DESTest.cs was failing with rev 38316...
2 // but the DES code was changed after the fix
3 // so the original code lives here forever ;-)
9 public const int keySizeByte
= 8;
11 internal static readonly ulong[] weakKeys
= {
12 0x0101010101010101, /* 0000000 0000000 */
13 0xFEFEFEFEFEFEFEFE, /* FFFFFFF FFFFFFF */
14 0x1F1F1F1F0E0E0E0E, /* 0000000 FFFFFFF */
15 0xE0E0E0E0F1F1F1F1 /* FFFFFFF 0000000 */
18 internal static ulong PackKey (byte[] key
)
20 byte[] paritySetKey
= new byte [keySizeByte
];
21 // adapted from bouncycastle - see bouncycastle.txt
22 for (int i
=0; i
< key
.Length
; i
++) {
24 paritySetKey
[i
] = (byte)((b
& 0xfe) |
25 ((((b
>> 1) ^
(b
>> 2) ^
(b
>> 3) ^
(b
>> 4) ^
26 (b
>> 5) ^
(b
>> 6) ^
(b
>> 7)) ^
0x01) & 0x01));
30 for (int i
= 0, sh
= 64; (sh
= sh
- 8) >= 0; i
++) {
31 res
|= (ulong) paritySetKey
[i
] << sh
;
38 byte[] wk2p
= { 0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x0E, 0x0E, 0x0E }
;
39 ulong lk
= PackKey (wk2p
);
40 foreach (ulong wk
in weakKeys
) {