A simple C program that implements a custom encryption algorithm for text files based on the Feistel network structure.
This program provides basic file encryption and decryption functionality using a simplified Feistel network cipher. It processes input files byte-by-byte, converting each character using a non-linear function and rounds of encryption.
IMPORTANT: This implementation is a proof-of-concept only and should NOT be used for securing sensitive information. It lacks many essential security features of modern cryptographic systems including:
- Insufficient key length and key management
- Limited block size (only 16 bits)
- Only a single round of encryption
- No initialization vectors or padding
- Vulnerable to numerous cryptographic attacks
This program is intended purely for educational purposes to demonstrate the basic concepts of a Feistel network.
- Encrypt text files to binary format
- Decrypt previously encrypted files
- Command-line interface with simple parameters
- Demonstration of basic Feistel network principles
Compile the program:
gcc -o cipher cipher.c
./cipher encrypt
This reads from sample.txt
and creates an encrypted cipher.dat
file.
./cipher decrypt
This reads from cipher.dat
and creates a decrypted decrypted.txt
file.
This program implements a simplified version of a Feistel network, a structure used in many block ciphers including DES. Key characteristics of Feistel networks:
- Data is split into two halves (left and right)
- The same algorithm is used for both encryption and decryption
- Multiple rounds are typically used to increase security (though this implementation uses only one)
- The encryption function only needs to be one-way, not invertible
-
The program uses a simplified Feistel structure with:
- A 16-bit block size (split into two 5-bit halves)
- A custom non-linear function (
non_linear()
) - A single round of encryption/decryption
-
The encryption process (
fn_round()
):- Splits each 16-bit value into left (5 bits) and right (5 bits) halves
- Applies the non-linear function to the right half
- XORs the result with the left half to create the new right half
- Uses the original right half as the new left half
-
The decryption process (
fn_deround()
) reverses these operations
- By default, only handles ASCII content correctly
- When processing UTF-8 text, each byte is encrypted separately rather than whole characters
- Uses only 16 bits for encryption, providing minimal security
- Implements only a single round (production Feistel ciphers use many rounds)