The encryption algorithm may be buggy
PRs are welcome in this repository
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
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
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.
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.
First, we need to take our initial key and we split that into two groups of 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.
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.
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
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.
Here are the S-Boxes listed and explained
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.