Skip to main content

pyserpent

PyPI version PyPI Downloads

[!CAUTION] Version 1.2.0 introduces a BREAKING CHANGE in CBC mode. The IV is now automatically prepended to the ciphertext. Data encrypted with v1.1.0 and earlier will not be compatible with the new decrypt function unless migrated. See below.

Install

pip install pyserpent

Quick Start - ECB

from pyserpent import Serpent

key = Serpent.generate_key()
serpent = Serpent(key)
plaintext = b"Hello, Serpent!!"

ciphertext = serpent.encrypt(plaintext)
decrypted = serpent.decrypt(ciphertext)

print(decrypted.decode())

Example Serpent CBC Mode

from pyserpent import Serpent, serpent_cbc_encrypt, serpent_cbc_decrypt

key = Serpent.generate_key()
plaintext = "Hello, Serpent!!"

# IV is generated automatically. To use your own: serpent_cbc_encrypt(key, plaintext, iv=your_iv)
ciphertext = serpent_cbc_encrypt(key, plaintext)
decrypted = serpent_cbc_decrypt(key, ciphertext)

print(decrypted.decode())

Migration from v1.1.0 to v1.2.0

To decrypt data created with version 1.1.0, you need to manually prepend the 16-byte IV to your ciphertext so the new version can recognize it.

If you used the default (zero) IV in v1.1.0:

# v1.1.0 used 16 zero bytes as default IV
old_iv = b'\x00' * 16
# Prepend it to your old ciphertext
prepared_ciphertext = old_iv + old_ciphertext

# Now it's compatible with v1.2.0 decrypt
plaintext = serpent_cbc_decrypt(key, prepared_ciphertext)

If you provided a custom IV in v1.1.0:

# Just prepend your IV to the ciphertext
prepared_ciphertext = your_old_iv + old_ciphertext
plaintext = serpent_cbc_decrypt(key, prepared_ciphertext)

Metadata

Release files for pyserpent 1.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyserpent 1.2.0
File Size Uploaded Provenance Actions
pyserpent-1.2.0.tar.gz 8.2 kB Without provenance Details for pyserpent-1.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pyserpent 1.2.0
File Interpreter ABI Platform Actions
pyserpent-1.2.0-py3-none-any.whl Python 3 none any Details for pyserpent-1.2.0-py3-none-any.whl

Total release size: 16.0 kB

Release files / pyserpent-1.2.0.tar.gz

Download URL pyserpent-1.2.0.tar.gz
Size 8.2 kB
Tags Source
SHA-256 checksum
How to use checksums
80bb908de84618c312d240f0498f9158e37d65a240d7f3959b6e51a4e1ddae8a
BLAKE2b-256 checksum
How to use checksums
2442284a84cf8cad5a6b2009a86f74006254860e431413e5e984290289db463a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.10

Release files / pyserpent-1.2.0-py3-none-any.whl

Download URL pyserpent-1.2.0-py3-none-any.whl
Size 7.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
99468594b5fc5e484933a6af89d4ba4d4455709363656bc24017196513884fd8
BLAKE2b-256 checksum
How to use checksums
7f56eedc2f6a0842c53b8106f6c4b51a2fc0a9cf9f1d449658cf76834be085c4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.10

Security for pyserpent 1.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page