# How is the initial permutation of DES created?

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?

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

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 built 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 transpose, 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.