Saturday, October 30, 2021

S-DES or Simplified Data Encryption Standard

 S-DES or Simplified Data Encryption Standard

The process of encrypting a plan text into an encrypted message with the use of S-DES has been divided into multi-steps which may help you to understand it as easily as possible.

Points should be remembered.
  1. It is a block cipher.
  2. It has 8-bits block size of plain text or cipher text.
  3. It uses 10-bits key size for encryption.
  4. It is a symmetric cipher.
  5. It has Two Rounds.

Let’s start the game!

Key Generation of S-DES or How to Generate the Key of Simplified DES

First and foremost, we need to generate a key. With the help of this key we will encrypt the message.
Now the interesting question is, how to generate the key, and where the key is to be used. Just follow the steps.

Step 1:

Just select a random key of 10-bits, which only should be shared between both parties which means sender and receiver.
As I selected below!

Select key:1010000010

Note:You can select any random number of 10-bits.

Step 2:

Put this key into P.10 Table and permute the bits.

P.10 Table:


Input
12345678910
Output Should be35274101986

As I put key into P.10 Table.
Input1010000010
Output1000001100

Now the output will be:

Key: 1000001100

Step 3:

Divide the key into two halves, left half and right half;
{1 0 0 0 0} | {0 1 1 0 0}

Step 4:

Now apply the one bit Round shift on each half:
Before round shift: {10000} | {01100}
After round shift: {00001} | {11000}
The output will be:
{0 0 0 0 1} {1 1 0 0 0}

Step 5:

Now  once again combine both halve of the bits, right and left. Put them into the P8 table. What you get, that will be the K1 or First key.
Combine: 0 0 0 0 1 1 1 0 0 0

Permute into 8bit table:
 
P8-Table
Input12345678910
Combine-bits0000111000
Output Should be637485109
Output bits10100100

See the table the 1 and 2 number of bits are removed and other are permuted, as 6 in place of one, 9 in place of 8 and so on.

The output and K1 or key One will be:

K1=1 0 1 0 0 1 0 0

Step6:

As we know S-DES has two round and for that we also need two keys, one key we generate in the above steps (step 1 to step 5). Now we need to generate a second bit and after that we will move to encrypt the plain text or message.

It is simple to generate the second key. Simply, go in step 4 copy both halves, each one consists of 5 bits. But be careful on the taking of bits. Select those halves which are output of first round shift, don’t take the bits which are not used in the first round. In simple words, take the output of first round shift in above step 4.

Which are: {00001} | {11000}

Step 7:

Now just apply two round shift circulate on each half of the bits, which means to change the position of two bits of each halves.
left half: 00001
Right half: 11000

After the two rounds shift on each half out-put of each half will be.
Left half: 00100
Right half: 00011
Combine both together: As: 0 0 1 0 0 – 0 0 0 1 1

Step 8:

Now put the bits into 8-P Table, what you get, that will be your second key. Table is also given in step 5.

But here the combinations of bits are changed because of two left round shift from step 5. Check it in depth.
Combine bits: 0 0 1 0 0 0 0 0 1 1

P.8 Table


Input
12345678910
Combine-bits0010000011
Output Should be637485109
Output bits01000011

The output of the bits are your Second key or K2:
K2: 0 1 0 0 0 0 1 1

Finally we create both keys successfully:

K1: 1 0 1 0 0 1 0 0 (see in step 5)
K2: 0 1 0 0 0 0 1 1 (see in step 8)

How To Encrypt the Plain Text into Cipher Text in S-DES After Generating Keys.

Now, let’s start Encryption of plain text into cipher text.

Encryption of Plain text into Cipher text in S-DES:

Come on do it, step by step.
Note: the size of input text is 8 bit and output also will be 8-bit. Or the block size is 8-bit/one byte always.

Step 1:

Suppose this is our plain text in binary which is 8-bit.

Plain text:
 01110010

Step 2:

Put the plain text into IP-8(initial permutation) table and permute the bits.

IP-8 table

Bits number12345678
Bits to be permuted01110010
Permute the bits26314857
Permuted bits10101001

Output is: 1 0 1 0 1 0 0 1

Step 3:

Now break the bits into two halves, each half will consist of 4 bits. The halves will be right and left.
Two Halves of the bits:

Left half {1 0 1 0} -right half {1 0 0 1}

Step 4:

Take the right 4 bits and put them into E.P (expand and per-mutate) Table.
Bits of right half: 1001

E.P Table

Right half bits1000
Number12345678
Expand bits41232341
Output of bits01000001

Output of right four bits will be 8 bits, after their expanding with the help of E.P table.

O-P
: 0 1 0 0 0 0 0 1

Step 5:
 Now, just take the output and XOR it with First key Or K 1 (which we created in previous topic that is how to generate key.).

XOR (⊕) them:

O-p
: 0 1 0 0 0 0 0 1
K1: 1 0 1 0 0 1 0 0
Output of XOR: 1 1 1 0 0101

Step 6:
 
Once again split the output of XOR’s bit into two halves and each half will  consist of 4 bits.

Splitting them into two halves:

Left half :{ 1 1 1 0} right half :{ 0101}
Now put the each half into the s-boxes, there is only two s-boxes. S-0 and S-1.

S-0

Col0123
Rows
001001110
111100100
200100111
311011110

S-1

Col0123
Rows
000011011
110000111
211000100
310010011

Note: put the left half into S-0 box and put the right half into S-1 Box.

But how to put them in into S-Boxes?

Take any half, (but don’t forget the above mentioned note..).
The most first and most last bit will be consider the row and other remaining, which are, 2 and 3, will be considered the columns.
See, here I’m taking the left half: which is 1 1 1 0.

Now I will take First and last bit which are: 1 and 0. These will be row.

And I also will take 2nd and 3rd bits which are: 11. These will be column number.
10 means=2rd row
11 means = 3rd col

See below how it will be the second row, and 3rd column. Please, remember the IP Addressing, such as 28 for 255.
101 =2+0=2
111 =2+1=3

Let’s check the 2nd row and 3rd column.

For left half we check the in S-0 . In which 2nd row and 3rd column.

The output is 00 for left half;

Now let’s take the right half and find the output of the right of in S-1 box.
Right half: 0101
Row: 0 1= 011=0+1=1
Col: 1 0=101=2+1=3

Which means the value will be in 1st row and 3rd column, let’s in check S-1.
The output will be: 11 for left half.

Step 7:

Now combine these two halves together.

Left half: {00} and right half: {11}
It will be: 0 0 1 1

Step 8:
 Now take these 4 bits and put them in P-4 (permutation 4) table and get the result.

P 4 Table

Numbers1234
Input0011
Output should be2431
Out-Put0110

Now the output is: 0 1 1 0

Step 9:

Now get XOR the output with left 4 bits of Initial Per-mutation. The left bits of initial per-mutation are in step 3, which are 1 0 1 0.( please, in step 3).
Let them to be XOR.

0 1 1 0
1 0 1 0

Out-put will be: 1 1 0 0

Step 10:

Now get the right half of the initial permutation, which is step 3, and combine that with this out- put.

The out-put of XOR in step 9: 1 1 0 0
Right half of IP (initial permutation): 1 0 0 1
Let’s combine both. 1 1 0 0 – 1 0 0 1= 1 1 0 0 1 0 0 1
Now the output is 8 bits.: 1 1 0 0 1 0 0 1

Step 11
: Now once again break the out-put into two halves, left and right;

Left: {1 1 0 0} right: {1 0 0 1}

Step 12:

Now swap both halves, which means put the left half in place of right and vice versa.

Result:
Left half: {1 0 0 1} right half: {1 1 0 0}

Step 13:

Now let’s take these halves and once again start the same procedure from step 2 or initial Permutation, BUT be careful on using key in this stage we use second key or K2 (not K1). And put that into IP-1 (IP inverse) Table. What you get will be your final cipher text.

Let me to do it in brief. You should check carefully what I did.
Ø 1 0 0 1 11 0 0

After initial permutation according to IP-8 table (see step 2)
Out-put will be: 0 1 0 1 1 0 1 0

Ø 
Now break it into two halves
Left {0 1 0 1} right {1 0 1 0}

Ø 
Now Take the right 4bits and put them into EP table, and get the result of 8 bits.
It will be: 0 1 0 1 0 1 0 1

Ø 
Let XOR it with K2.
K2: 0 1 0 0 0 0 1 1

Out-put of EP0 1 0 1 0 1 0 1
Out- Put: 0 0 0 1 0 1 1 0

Ø 
Once again split the output of XOR’s bit into two halves:
Left: {0 0 0 1} right: {0 1 1 0}

Ø 
Now put each half in S-Boxes, which are S-0 and S-1:

Note: put the left half into S-0 box and put the right half into S-1 Box.

Before that get Rows and column:

Left: 0 0 0 1
Row: 0 1= 1
Col: 0 0 = 0

Let find the row and column of left, in S-0, the value is row number one and col number Zero.

It will be. 1 1
Ø now check the right half: 0 1 1 0
Row: 0 0=0
Col: 1 1= 3

Let's find the row and column of right, in S-1, the value is row number zero and col number three.

It will be: 11
Ø Now combine both halves together.
It will be: 1 1 1 1

Ø 
Now take these 4 bits and put them in P-4 ( Per-mutation 4) table and get the result.

The out-put also will be: 1111 after permutation.

Ø 
Now get it XOR with left 4 bits of Initial Per-Mutation.
1 1 1 1
XOR
0 1 0 1

Out-put
:1 0 1 0

Ø 
Now get the right half of the initial permutation and combine that with this out- put.
1 0 1 0 - 0 1 1 0

Ø 
Now once again break the it into two halves, left and right
Left: {1 0 1 0} right: {0 1 1 0}

Ø 
Now swap both halves, which means put the left half in place of right and vice versa.
0 1 1 0 1 0 1 0

Ø 
Now put it into IP-1 Table which is :

IP-1 Table

Numbers12345678
input01101010
Out-put to be26314857
Out-Put10100011

Out-Put is the cipher text. Which is: 1 0 1 0 0 0 1 1

Finally we Encrypted successfully our plain text: 01110010 into cipher text which is:

1 0 1 0 0 0 1 1

Note: We have encrypted simply a single block.

You can also find the post in my blog.

No comments:

Post a Comment

No String Argument Constructor/Factory Method to Deserialize From String Value

  In this short article, we will cover in-depth the   JsonMappingException: no String-argument constructor/factory method to deserialize fro...