This project performs block and stream cipher encryption and decryption on plain text given a key.
Run the following command in the terminal. Makefile is visited and ran to create an executable called 'cipher' which will make the running of the program easy moving forward.
make
The program requires five command-line arguments in order as follows:
- Cipher Function Type: 'B' - Block cipher, or 'S' - Stream cipher. Which method of encryption/decryption are you gonna use?
- Input File Name: Input file that has the plaintext for encryption or ciphertext to be decryption.
- Output File Name: Output file to which the encrypted/decrypted output will be written.
- Key File Name: Key file containing the symmetric key. Key size should be 16 bytes for Block Encryption. For Stream Encryption, can be of any length.
- Mode of Operation: 'E'- encryption or 'D' - decryption.
./cipher [B/S] [Input File Name] [Output File Name] [Key File Name] [E/D]
- Encrypt
plaintext.txt
using a block cipher withkey.txt
:./cipher B plaintext.txt encrypted.txt key.txt E
- Decrypt
encrypted.txt
using a stream cipher withkey.txt
:./cipher S encrypted.txt decrypted.txt key.txt D
- Argument Validation: Ensures the correct number of arguments, cipher type, and mode of operation are provided.
- File Processing: Handles input and key files, verifying that they exist.
- Block Cipher:
- Processes encryption/decryption in 128-bit blocks.
- Adds padding (0x81) for blocks that are less than 128 bits.
- Performs an XOR operation followed by a byte-swapping algorithm.
- Stream Cipher:
- Executes an XOR operation on the input data with the key, repeating the key if needed.
The program features basic error handling for incorrect arguments and file read/write issues. Error messages are generated if any problems occur.