4
$\begingroup$

I am creating a program in C language with DES (Data Encryption Standard) functionality, but don't know how to apply the initial permutation.

Is it achieved by swapping the values? If "yes", then how is the index of the original message created?

$\endgroup$
3
  • $\begingroup$ You should check out this: codemiles.com/c-code-examples/… Thanks. $\endgroup$
    – Yang Xia
    Sep 24, 2013 at 11:55
  • $\begingroup$ It's a bitwise permutation. What values are you thinking might be swapped? $\endgroup$
    – B-Con
    Sep 25, 2013 at 23:35
  • $\begingroup$ You haven't describe the interface type for your DES function (e.g. array of bits, arrays of bytes, array of .., 64 bit value). $\endgroup$
    – user1430
    Nov 20, 2013 at 16:57

1 Answer 1

5
$\begingroup$

The Inital Permutation is defined in the DES specification. This spec numbers bits from 1 to 64 in big-endian reading order. The table gives the bit numbers in the 64-bit block input, to be selected to build the L and R registers:

58  50  42  34  26  18  10   2      L, bits  1 to  8
60  52  44  36  28  20  12   4      L, bits  9 to 16
62  54  46  38  30  22  14   6      L, bits 17 to 24
64  56  48  40  32  24  16   8      L, bits 25 to 32
57  49  41  33  25  17   9   1      R, bits  1 to  8
59  51  43  35  27  19  11   3      R, bits  9 to 16
61  53  45  37  29  21  13   5      R, bits 17 to 24
63  55  47  39  31  23  15   7      R, bits 25 to 32

This table is extremely regular: each value is 8 more than the value on its right, if any. More: the transformation is a near transposition, and becomes one if we make a left/right mirror, and bring the lines with octets of R before the corresponding lines for L.

That regularity comes from the initial implementation of DES in hardware: the plaintext was loaded sequentially as 8 octets, with at each of 8 loads each of the 8 bits of an octet entering an 8-bit shift register, 4 of which for L, 4 of which for R, with these 8 shift registers clocked simultaneously. A natural software implementations can mimic that (among other possibilities).

For the highest performance in software, see Richard Outerbridge's implementation. That uses a general technique to implement transpose using wordwide operations, tunes it to the slightly irregular transpose that IP is, and (in some variants) performs a 32-bit rotate by 1 bit of L and R than can speed-up the rest of DES.

Other than easing hardware implementation, the initial and final permutation have no know design purpose. They do not increase (or decrease) security of DES. They slow software implementation a little, but there is no indication that's explicitly among the design goals (which broadly are to make DES fast, and secure from all attacks except brute force, see this).

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.