Registry / auth-security / twofish

twofish

JSON →
library0.3.0pypypiunverified

The `twofish` library provides Python bindings for a C implementation of the Twofish symmetric key block cipher, designed by Niels Ferguson. Twofish is a 128-bit block cipher supporting key sizes up to 256 bits, and was a finalist in the AES competition. The current version is 0.3.0, with the last PyPI release in 2013, and the official GitHub repository was archived in January 2025, indicating it is no longer actively maintained.

pip install twofish
INSTALL
IMPORT
SIG · TWOFISH
T
twofish
auth-securitypythonv0.3.0
Install
Import
Disk
Pass rate
0/ 10
Env Coverage0 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v? · pip install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
build_error
glibc
py 3.103.920 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Twofish
from twofish import Twofish
import twofish

This example demonstrates basic encryption and decryption of a single 16-byte block using a 128-bit key. Note that this library explicitly handles only 16-byte blocks, and higher-level cipher modes (like CBC or CTR) must be implemented externally or by using a different library.

from twofish import Twofish import os # Key must be 16, 24, or 32 bytes (128, 192, or 256 bits) # For a real application, use a securely generated random key key = os.urandom(16) # 128-bit key cipher = Twofish(key) # Data blocks must be exactly 16 bytes plaintext_block = b'This is a 16-byt' ciphertext_block = cipher.encrypt(plaintext_block) decrypted_block = cipher.decrypt(ciphertext_block) print(f"Original: {plaintext_block}") print(f"Encrypted: {ciphertext_block.hex()}") print(f"Decrypted: {decrypted_block}")
Debug
Known issues
breakingThe `keybase/python-twofish` GitHub repository, which hosts the code for this PyPI package, was archived by its owner on January 22, 2025. This means the library is no longer actively maintained and will not receive updates or bug fixes.
fix
Consider migrating to a actively maintained cryptographic library (e.g., `cryptography` or `PyCryptodome`) that provides Twofish or other robust ciphers with full mode support.
affects: 0.3.0 and older
gotchaThis library only implements the core Twofish block cipher, operating exclusively on 16-byte (128-bit) data blocks. It *does not* include higher-level cipher modes (such as CBC, CTR, GCM) or padding schemes.
fix
For encrypting data larger than 16 bytes or variable-length messages, you must manually implement a secure block cipher mode and appropriate padding. Using the raw block cipher directly for more complex data can lead to severe security vulnerabilities. It is highly recommended to use a more comprehensive cryptographic library that handles these complexities for you.
affects: 0.3.0 and older
gotchaKeys must be binary strings (bytes in Python 3) and can only be 16, 24, or 32 bytes long (corresponding to 128, 192, or 256 bits). Providing an invalid key length will result in a `KeyError`.
fix
Ensure your encryption key is generated securely and precisely matches one of the supported lengths (16, 24, or 32 bytes) before passing it to the `Twofish` constructor.
affects: 0.3.0 and older
deprecatedThe library explicitly states compatibility with Python 2.6, 2.7, and 3.3. While it might still function on some newer Python 3 versions, it is not officially supported and may encounter compatibility issues or unexpected behavior.
fix
For modern Python development, use alternative libraries like `cryptography` or `PyCryptodome`, which offer broad compatibility and active maintenance for Twofish and other cryptographic primitives.
affects: 0.3.0 and older
Upgrade
Version history
0.3.0latest on PyPI · released Nov 15, 2013
Audit
Dependencies

No dependency data recorded yet.

Agent activity
52 hits · last 30 days
node
46
OpenAI (training)
1
Resources