Skip to content

539hex/feistel-network-poc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Feistel Network Encryption

A simple C program that implements a custom encryption algorithm for text files based on the Feistel network structure.

Overview

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.

⚠️ Security Disclaimer

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.

Features

  • Encrypt text files to binary format
  • Decrypt previously encrypted files
  • Command-line interface with simple parameters
  • Demonstration of basic Feistel network principles

Usage

Compile the program:

gcc -o cipher cipher.c

Encryption

./cipher encrypt

This reads from sample.txt and creates an encrypted cipher.dat file.

Decryption

./cipher decrypt

This reads from cipher.dat and creates a decrypted decrypted.txt file.

How it Works

Feistel Network Background

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

Implementation Details

  1. 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
  2. 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
  3. The decryption process (fn_deround()) reverses these operations

Limitations

  • 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)

References

About

A POC of text encryption using Feistel Network

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages