Saturday, 27 August 2016

Data Encryption Standard (DES)

Hello everyone. In this blog, I will be discussing about first Symmetric Key
Cryptography - Data Encryption Standard (DES) - in details.

DES was developed by IBM in 1970s and later standardized in public by NSA
in 1977. It is a block cipher. It encrypts data in blocks of size 64 bits
each. DES uses heavily bit operations. It uses a key of 56 bit length. The
same algorithm and the key is used for decryption process.

Actually, the original key is of 64 bit length. But for parity checking
purpose, every 8th bit is discarded from the original key, making it a
key of 56 bit length. Now what I have done here is that I took ASCII value
of each character from the plain text and the key and converted to binary
digits of 8 bit length. Now this happens that the total length of the plain
text and the key may not be an exact multiple of 64. So I appended zeroes
at the end of the plain text and the key in such a way that they become a
multiple of 64. One important thing to note is that the key size cannot be
greater than 8 characters. As each character represents 8 bits and the
size of key cannot be greater than 64 bits, hence key size cannot be
more than 8 characters.

Now divide the plain text in blocks of 64 bits. Take each block one by one.
And start encrypting them with DES. The DES involves the following steps :



1. Initial Permutation:
   As the name suggests, it rearranges the first Plain Text block bits
   according to the IP table. That is, the first bit of the permuted text
   block will be the 58th bit of the first plain text block, the second
   bit will be the 50th bit of the first plain text block and so on. Now
   divide the permuted text into two halves - 32 bit Left Plain Text (LPT)
   and 32 bit Right Plain Text (RPT).



2. 16 Rounds:
   a) Key Transformation:
      Divide the 56 bit Key into two halves - C Key (28 bit) and
      D Key (28 bit). Perform Left Circular Shift to C Key and D Key
      according to the Circular Left Shift Table.



      After the shift, join C Key and D Key again to make Shifted Key of
      56 bit.

   b) Compression Permutation:
      This step involves selection of 48 bits out of 56 bits of Shifted
      Key. In other words, Shifted Key is compressed and permuted at the
      same time. It is done according to the Compression Permutation table.
      For example, the first bit of Compressed Key will be the 14th
      bit of the shifted key and so on.



   c) Expansion Permutation:
      Recall that after Initial Permutation, we had LPT and RPT, each of 32
      bit length. During this step, RPT is expanded from 32 bit to 48 bit.
      Besides this, it is permuted as well. Hence the Expansion Permutation.
      At first, 32 bit RPT is divided into 8 blocks of 4 bits each. Then
      each 4 bit block is expanded to 6 bit block by adding two more bits.
      One bit at the beginning of the 4 bit block and the other bit at the
      end of that 4 bit block.



      This is how it is done. For simplicity of the computation, this process
      has been stored in the Expansion Permutation table. After this step, RPT
      has 8 blocks of 6 bits each, making it a 48 bit Expanded RPT.



   d) XOR:
      This step involves the bitwise XOR operation between the Expanded RPT
      of 48 bit length and the Compressed Key of 48 bit length. This results
      in the XORed RPT of 48 bit length.

   e) S Box Substitution:
      The XORed RPT is fed into the S Box Substitution step. Here, the XORed
      RPT is again divided into 8 blocks of 6 bit each. For each block, there
      is a separate S Box table which gives 4 bit output. Hence, there are 8
      S Box tables corresponding to 8 blocks. For example, Block 1 will be
      fed to S Box 1, Block 2 to S Box 2 and so on. S Box tables consist of
      4 rows and 16 columns. Each row contains 0 to 15 numbers in haphazard
      manner. These 0 to 15 numbers can be represented with 4 bits. As we know,
      each block contains 6 bits, these 6 bits tell us the row number and the
      column number of the S Box table corresponding to that block. The 1st
      bit and the 6th bit determines the row number whereas 2nd, 3rd, 4th and
      5th bits determine the column number. The value that is obtained at the
      intersection of the row number and the column number is the 4 bit output
      of the S Box table. So each of the 8 blocks gives 4 bit output, giving
      rise to 32 bit S Box RPT.






   f) P Box Permutation:
      In this step, S Box RPT will be permuted according to the P Box table
      giving rise to P Box RPT.



   g) XOR and Swap:
      During all these operations, the LPT was left untouched so far. So in
      this step, P Box RPT of 32 bit length and the untouched LPT of 32 bit
      length is XORed. The XORed text is stored in the RPT and the original
      RPT is stored in the LPT. After this, again the next round starts.
      That is why it is called 16 Rounds.



3. At the end of the 16 rounds, the Final Permutation is done on the combined
   LPT and RPT giving rise to 64 bit first Cipher Text block. It is done
   according to the Final Permutation table.



4. All the previous steps i.e. 1,2 and 3 is performed for all the other Plain
   Text blocks to get the corresponding Cipher Text blocks. At the very end,
   all the Cipher Text blocks are combined to obtain the final cipher text.

Here is the file that contains the C# code for DES. As it is a very long code
(574 lines of code more specifically), that's why I have provided the file.
https://drive.google.com/file/d/0B9s_U5HeDEtAcWJfMl81VloycFE/view?usp=sharing

Here is the theoretical video of DES:


Here is the working video of DES:


In this modern world, people don't use Single DES as it is vulnerable to
heavy attacks. That's why they prefer more Double DES and Triple DES.
In Double DES, DES is done twice with 2 different keys.



In Triple DES, DES is done thrice. Here Triple DES can be performed with
3 keys or even 2 keys.





That's the end of this blog. I hope you find my blogs useful. Till then
stay tuned and keep coding.

Practice Page Link:
http://handsoncrypto.azurewebsites.net/PracticePage.aspx

No comments:

Post a Comment