A simple GUI implementation of 128 bit AES encryption (single round till now) in C#
- .NET 8 SDK: Install the .NET 8 SDK from the official .NET website or using a package manager like Chocolatey.
- .NET 8 SDK: If you haven't already, install the .NET SDK on your machine.
A typical AES encryption algorithm runs for 10 rounds -each round comprising of 4 processes.The 1st round is shown below -
Note - We have restricted our algorithm to a single round for the sake of simplicity.
The 16 input bytes are substituted by looking up a fixed table (S-box) given in design.
Each of the four rows of the matrix is shifted to the left. Any entries that ‘fall off’ are re-inserted on the right side of row. Shift is carried out as follows −
-
First row is not shifted.
-
Second row is shifted one (byte) position to the left.
-
Third row is shifted two positions to the left.
-
Fourth row is shifted three positions to the left.
-
The result is a new matrix consisting of the same 16 bytes but shifted with respect to each other.
Each column of four bytes is now transformed using a special mathematical function. This function takes as input the four bytes of one column and outputs four completely new bytes, which replace the original column. The result is another new matrix consisting of 16 new bytes. We have used the Galois Field Lookup tables for the sake of simplicity.
The 16 bytes of the matrix are now considered as 128 bits and are XORed to the 128 bits of the round key. If this is the last round then the output is the ciphertext. Otherwise, the resulting 128 bits are interpreted as 16 bytes and we begin another similar round.
The process of decryption of an AES ciphertext is similar to the encryption process in the reverse order. Each round consists of the four processes conducted in the reverse order −
- Add round key
- Mix columns
- Shift rows
- Byte substitution
- Run the gui.py script to start the application
- Select the encrypt tab
- Enter the text you want to encrpyt. You can also select a txt file that contains the text to be encrypted
- Enter a 16 character key (make sure to remember this otherwise you wont be able to decrypt later on)
- Enter the name of the file you wish to be saved without any extensions
- Click encrypt. it will be saved as txt fille in the Encrypted folder
- Select the decrypt tab
- Enter the name of the encypted file (no need to worry about the relative path,just enter file name without extension)
- Enter the 16 character key used for encryption
- Click decrypt. it will be saved in the Decrypted folder as a txt file.