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 PyPI

pip install katcrypt

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.1.tar.gz (9.4 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.1-py3-none-any.whl (10.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: katcrypt-0.1.1.tar.gz
  • Upload date:
  • Size: 9.4 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.1.tar.gz
Algorithm Hash digest
SHA256 e2ba5b7c4c895f5c70af25d91bc1a8b98e72c1286b2522866fc2f39fc832e19a
MD5 9e1304eac9aab4d96040b32b2b79403c
BLAKE2b-256 2a9ecf97fd6024d22227ae41d4acc6977f673901a684e04fc62616b4a46540a4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: katcrypt-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 10.4 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 501479394e3e3f405d4ee500043ec661978a1415055f4906d9448996b113c755
MD5 e13165d7e94f4a41f3206a6225a6e69c
BLAKE2b-256 71ee62d4e7188a56e10599c3e84099c91f5ac92d4abca5f5921b7a724ba24f38

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