Skip to main content

A pure-Python Feistel Network Block Cipher Implementation

Project description

PyFeistel

A pure-Python Feistel Network Block Cipher Implementation.

** Documentation**: For a comprehensive analysis of the mathematical foundations, memory model, and architectural decisions, please consult the PyFeistel Design Document.

Features

  • Custom Feistel Network: 16-round architecture with non-linear Key Schedule.
  • Modes of Operation: CBC (Cipher Block Chaining) and CTR (Counter) modes.
  • Educational Design: Pure Python implementation using bytearray for clarity and secrets for security.
  • Visualization: Tools to visualize cryptographic properties like the Avalanche Effect.

Installation

pip install .

Testing & Verification

The library includes a robust test suite to verify both correctness and cryptographic properties.

1. Unit & Functional Tests

Verifies correct round-trip encryption/decryption for all modes (CBC, CTR) and padding logic.

  • Command: pytest tests/test_core.py tests/test_modes.py
  • Result: ✅ Passed (Correctness verified)

2. Avalanche Effect

Verifies that flipping 1 bit in the plaintext flips approximately 50% of bits in the ciphertext.

  • Command: pytest tests/test_avalanche.py
  • Result: ✅ Passed (Average Hamming Distance ~64 bits)

3. NIST Statistical Analysis

Integrated with the NIST SP 800-22 test suite (via nistrng) to check for statistical randomness.

  • Command: python tests/test_nist_stats.py
  • Scope: Checked 160,000 bits of CTR-mode output.
  • Results: verified basic randomness properties.
    • Monobit (Frequency): ✅ PASS (p=0.50) - Output has equal 0s/1s.
    • Runs Test: ✅ PASS - Bit transition frequency is random.
    • Spectral/Complexity: ⚠️ Mixed (Sample size limitation vs educational scope).

Examples

Avalanche Effect Visualization

PyFeistel includes a visualization tool to demonstrate the Avalanche Effect.

You can run the visualization script:

python examples/visualize_avalanche.py

This script generates a heatmap tracing the bit differences through all 16 rounds of the cipher.

Avalanche Effect Heatmap

Figure: Heatmap showing bit diffusion. Dark pixels represent bit differences between two encrypted blocks differing by only 1 bit in the plaintext. Note how the differences spread (diffuse) rapidly after the first few rounds.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyfeistel-0.1.0.tar.gz (59.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyfeistel-0.1.0-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file pyfeistel-0.1.0.tar.gz.

File metadata

  • Download URL: pyfeistel-0.1.0.tar.gz
  • Upload date:
  • Size: 59.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.11

File hashes

Hashes for pyfeistel-0.1.0.tar.gz
Algorithm Hash digest
SHA256 75665b8d8240590e7a67e690f18464333a44225e7420774d67c6c46736b5243b
MD5 bb2ee37abdb3f71b86a3efa74a4cb297
BLAKE2b-256 218d8179444399c9073ebbcde2b3759b9b6f380d97047eb1e4e101270f61ad6e

See more details on using hashes here.

File details

Details for the file pyfeistel-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pyfeistel-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.11

File hashes

Hashes for pyfeistel-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d32d8d77eb73664deb75ec822c0b1cc0a486b1cc6e116ee3cda4f8fd77b2782c
MD5 f91cc8db8b87df81fec3db0f06032975
BLAKE2b-256 493212afb4d9c58507bab5084fe51f50ed84d45af0a1c5a4aa349f7479bc09fe

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page