Educational Python implementation of the Schmidt–Samoa public-key cryptosystem.
The repository explores the algorithm's key-generation, encryption, and decryption operations and includes utilities for probable-prime generation, modular arithmetic, and text-to-integer conversion. It is maintained as a cryptography study and software-engineering project.
Security scope: this implementation has not been independently audited, standardized, or validated for production cryptographic use. Do not use it to protect real secrets. For production systems, use established protocols and maintained cryptographic libraries with appropriate review and validation.
- Schmidt–Samoa key-pair generation
- integer encryption and decryption
- string-to-integer conversion helpers
- chunking helpers for inputs larger than a single modulus operation
- Miller–Rabin probable-prime testing
- random candidate generation using Python's
secretsmodule - iterative extended Euclidean algorithm
- modular inverse calculation
- immutable key data classes
For primes p and q, this implementation represents the public modulus as:
n = p²q
and computes the private exponent using the modular inverse required by the Schmidt–Samoa construction. Encryption and decryption are implemented with Python's modular exponentiation (pow(..., ..., modulus)).
The implementation is intended to make those mathematical operations inspectable in code rather than provide a deployment-ready cryptographic API.
from schmidt_samoa import SchmidtSamoa
public_key, private_key = SchmidtSamoa.generate_keypair(bits=1024)
message = 123456789
ciphertext = SchmidtSamoa.encrypt(message, public_key)
plaintext = SchmidtSamoa.decrypt(ciphertext, private_key)
assert plaintext == messageFor demonstrations and additional test cases:
python demo.py
python examples.py.
├── schmidt_samoa.py core implementation
├── demo.py small usage demonstration
├── examples.py extended examples and regression exercises
├── SECURITY.md scope and security caveats
├── CHANGELOG.md implementation history
├── requirements.txt
└── LICENSE
Earlier versions of this project used a recursive extended-GCD implementation and less disciplined random-number generation. Later revisions moved to an iterative extended-GCD implementation, Python's secrets module for random candidates, and a stateless API.
Those changes are useful examples of how implementation details can affect a cryptographic experiment. They should not be interpreted as proof that the resulting library is secure for production use.
- no independent cryptographic audit;
- no standards or compliance validation;
- no interoperable wire/key serialization format;
- no established padding or higher-level protocol around the primitive;
- probable-prime testing and parameter choices are implementation decisions, not a claim of FIPS compliance;
- timing behavior and side-channel resistance have not been evaluated;
- examples are intended for learning and regression checking rather than certification testing.
The project documents my work with public-key cryptography, number-theoretic algorithms, Python implementation choices, debugging, and iterative hardening of a research prototype. Keeping the limitations explicit is part of the project: cryptographic code should not gain security claims simply because basic functional tests pass.