pycrypt
A pure Python implementation of cryptographic primitives, written in a clean, Pythonic, and type-safe way.
⚠️ Disclaimer:
pycryptis an educational cryptography library. It is not safe for production use. Use only for learning how cryptographic algorithms work under the hood.
Do not roll your own crypto in production code. Use a safe, audited library that has been vetted by professionals.
Overview
pycrypt implements major cryptographic primitives from scratch in pure Python
with minimal dependencies. It is designed for learners and developers interested
in the inner workings of cryptography.
Features
| Category | Algorithm | Description |
|---|---|---|
| Asymmetric | RSA | OAEP encryption/decryption, PSS signing/verification |
| Diffie–Hellman (DH) | Modular exponentiation and HKDF-based key derivation | |
| Symmetric | AES | ECB, CBC, CTR, and GCM modes |
| Hashing | SHA-1, SHA-256 | HMAC and HKDF included |
Project Structure
pycrypt/
├── asymmetric/
│ ├── dh/
│ │ ├── core.py
│ │ ├── groups.py
│ │ └── keyformat.py
│ └── rsa/
│ ├── core.py
│ ├── keyformat.py
│ └── utils.py
├── hash/
│ ├── sha/
│ │ ├── core.py
│ │ ├── hmac.py
│ │ └── variants.py
├── symmetric/
│ └── aes/
│ ├── core.py
│ ├── modes.py
│ └── utils.py
├── utils/
│ ├── asn1.py
│ ├── padding.py
│ └── utils.py
└── main.py
Installation
pip install pycrypt-lib
Examples
Diffie–Hellman (DH) Key Exchange
from pycrypt.asymmetric import DH
params = DH.generate_parameters(2048)
alice_priv = params.generate_private_key()
bob_priv = params.generate_private_key()
alice_shared = alice_priv.exchange(bob_priv.public_key())
bob_shared = bob_priv.exchange(alice_priv.public_key())
assert alice_shared == bob_shared
print(f"Shared secret: {alice_shared.hex()}")
RSA Encryption and Signing
from pycrypt.asymmetric import RSAKey
key = RSAKey.generate(2048)
message = b"Hello RSA!"
cipher = key.oaep_encrypt(message)
plain = key.oaep_decrypt(cipher)
signature = key.pss_sign(message)
assert key.pss_verify(message, signature)
AES (GCM Mode)
from secrets import token_bytes
from pycrypt.symmetric import AES_GCM
key = token_bytes(16)
nonce = token_bytes(12)
aes = AES_GCM(key)
ciphertext, tag = aes.encrypt(b"Top Secret", nonce=nonce)
plaintext = aes.decrypt(ciphertext, nonce=nonce, tag=tag)
print(plaintext.decode())
SHA-256 Hash
from pycrypt.hash import SHA256
sha = SHA256()
sha.update(b"hello world")
print(sha.hexdigest())
License
pycrypt is licensed under the MIT License.
See LICENSE for the full text.
⚠️ Note: This library is not secure for production use. It is a learning and exploration tool only.
Links
Cryptography Reference Standards
Metadata
Release files for pycrypt-lib 1.1.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pycrypt_lib-1.1.4.tar.gz | 28.3 kB | Without provenance | Details for pycrypt_lib-1.1.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pycrypt_lib-1.1.4-py3-none-any.whl | Python 3 | none | any | Details for pycrypt_lib-1.1.4-py3-none-any.whl |
Total release size: 63.5 kB
Release files / pycrypt_lib-1.1.4.tar.gz
| Download URL | pycrypt_lib-1.1.4.tar.gz |
|---|---|
| Size | 28.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
462ccb797ef7be4459e99f0d56fb9a14b7c5891d01258438f7d6eb04d63cc97d
|
|
BLAKE2b-256 checksum How to use checksums |
e6672e4e9d920fe82c0e6bc513e854e332d5e76698e80ca30e0b17146b60e480
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / pycrypt_lib-1.1.4-py3-none-any.whl
| Download URL | pycrypt_lib-1.1.4-py3-none-any.whl |
|---|---|
| Size | 35.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
85220766b60f6c2fdcb9233f8a9961dc06aae21ccdfca374fa66f0b01567b35e
|
|
BLAKE2b-256 checksum How to use checksums |
3bb64aeb8bd8cebe424ae06f923fe3545264fda8f3a09401b0c23cb0bcee53a3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for pycrypt-lib 1.1.4
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.