Skip to main content

A pure Python encryption library supporting a variety of algorithms and modes

Project description

KatCrypt

A pure Python cryptographic library implementing multiple block ciphers and encryption modes from scratch.

Overview

KatCrypt provides implementations of modern block ciphers and standard modes of operation, built entirely in Python without external cryptographic dependencies. All algorithms are implemented from their original specifications with comprehensive test vector validation.

Supported Algorithms

Block Ciphers

  • AES (Advanced Encryption Standard) - 128, 192, and 256-bit keys
  • MARS - IBM's AES competition finalist
  • Threefish - Block cipher from the Skein hash function family

Modes of Operation

  • ECB (Electronic Code Book)
  • CBC (Cipher Block Chaining)
  • CFB (Cipher Feedback)
  • OFB (Output Feedback)
  • CTR (Counter Mode)
  • GCM (Galois/Counter Mode with authentication)

Installation

From Source

git clone https://github.com/hashwalker/katcrypt.git
cd katcrypt
pip install -e .

Requirements

  • Python 3.7+
  • No external dependencies

Usage

Functional API

import katcrypt
from katcrypt.utils import generate_key, generate_iv

# Basic encryption example
key = generate_key(256)  # 256-bit key for AES
iv = generate_iv(16)     # 128-bit IV
plaintext = b"Hello, World! This is a secret message."

print(f"Original: {plaintext}")

# Encrypt the message
ciphertext = katcrypt.encrypt(
    cipher="aes", 
    mode="cbc", 
    key=key, 
    plaintext=plaintext, 
    iv=iv
)

print(f"Encrypted: {ciphertext.hex()}")

# Decrypt the message
decrypted = katcrypt.decrypt(
    cipher="aes", 
    mode="cbc", 
    key=key, 
    ciphertext=ciphertext, 
    iv=iv
)

print(f"Decrypted: {decrypted}")
print(f"Success: {plaintext == decrypted}")

Object-Oriented API

from katcrypt.ciphers.aes import AES
from katcrypt.modes.cbc import CBC
from katcrypt.utils import generate_key, generate_iv

# Setup
key = generate_key(256)
iv = generate_iv(16)
plaintext = b"Object-oriented encryption example!"

print(f"Original: {plaintext}")

# Create cipher and mode objects
cipher = AES(key=key)
mode = CBC(cipher)

# Encrypt and decrypt
ciphertext = mode.encrypt(plaintext, iv)
print(f"Encrypted: {ciphertext.hex()}")

decrypted = mode.decrypt(ciphertext, iv)
print(f"Decrypted: {decrypted}")
print(f"Success: {plaintext == decrypted}")

Project Structure

katcrypt/
├── ciphers/             # Block cipher implementations
├── modes/               # Mode of operation implementations  
├── utils.py             # Cryptographic utilities
├── constants/           # Algorithm constants and tables
└── test_vectors/        # Test vectors and validation

Testing

The library includes comprehensive test vectors from official sources:

python test_vectors/aes_test_vectors.py
python test_vectors/mars_test_vectors.py  
python test_vectors/threefish_test_vectors.py

Test vectors validate against:

  • NIST AES test vectors
  • IBM MARS reference implementation
  • Threefish reference vectors

Security Notice

This library is intended for educational and research purposes only.

It is not suitable for production use as it lacks:

  • Constant-time implementations
  • Side-channel attack protections
  • Formal security audits
  • Timing attack mitigations

For production applications, use established libraries such as cryptography or pycryptodome.

License

MIT License - see LICENSE file for details.

Author

Created by hashwalker

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

katcrypt-0.1.0.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

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

katcrypt-0.1.0-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: katcrypt-0.1.0.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for katcrypt-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d67c5f3e0930c4ad21718b875ffa58f0633cfd255af83ff1c8cef38c379bc75d
MD5 1af0f04476be9311920086d99e8e45ec
BLAKE2b-256 676c2d3dcf1a4eb00734fdf3db0fabca826b9540b019839bcee796923a76b6b6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: katcrypt-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for katcrypt-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 97deba2d17030f4a0b3953c69f527effc139119e5f718caeee7beb3d684d17e1
MD5 1122050db68ce812f791d92408c1c86e
BLAKE2b-256 38cc4e21e8936463301ae4c85f4c7edf523f6a7d89be123a60d016685ed49bd2

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