The encryption algorithm may be buggy
PRs are welcome in this repository

User Input

Ascii input

Ascii key

In the first step you take the user input, which is a key and a string. Here the String input is limited to 8 characters to make it easier. The key is always limited to 8 characters. Both of the Strings are converted to binary ASCII

Setting up

Delete every 8th bit from the key

Then we delete every 8th bit off the key, making it a 56-Bit key. Those bits can be used as parity bits, but mostly are discared

Not take the initial permutation table

And move the bits to their new position

Next we take the initial permutation table and move the bits to their new position. This is done by taking the bit's corresponding position on the permutation table and moving it to the position by the table. The inital permutation has no cryptographic significance, and was most likely done to ease the compalibily with the 70s hardware.

Our left plain text is the upper half

And the right plain text is the lower half

Now we split the plain text into two halves. The left half is the upper half of the plain text, and the right half is the lower half of the plain text. The plain text is 64 bits long, so each half is 32 bits long.

How a round works

Take the first 28 Bits

And the second 28 Bits

First, we need to take our initial key and we split that into two groups of 28 Bits.

Shift the first 28 Bits

And the second 28 Bits

Then we need to shift our key by a predetermined amount, which depends on the round we are at. It's one index for rounds 1, 2, 9, 16 and two for all other rounds.

Take the compression permutation table

And move the bits to their new position

We take the compression permutation table, and move the bits from the index that is written on the table onto the index that it is written onto. E.g. the bit on index 14 is moved onto index 1, because the tables index 1 holds the value 14. This is done to make the key 48 bits long.

Split the right plain text into 4 bit chunks

And turn it into 6-Bit chunks

Then we take the right plain text and part it in 4 bit chunks, and expand those chunks to 6 bits. This is done by taking the last bit from the preceding table and adding it to the beginning and taking the first bit from the next table and adding it to the end. With this we turn the 32 bits into a 48-Bit output, which we will need later, as we apply a 48-Bit key. This example is only for the left side, but we do this to both sides

Take your expanded key

And apply XOR to the right side

We apply this step to the right time every time we are currently in an even step. Otherwise we do this to our our left side.

Take the first 6 bits from our XOR

And apply the first S-Box to those

Here are the S-Boxes listed and explained

Take the left side from before

And XOR with our output

This process is called the Feistel scheme. We take the left side from before and XOR it with our output. And on the next round we take the right side from before and XOR it with our output. This is done 16 times, which gives us an output.

The final permutation

Take the final results as one table

And apply the final permutation table

Which leaves us with following result