cryptograms
A Python package for solving simple substitution ciphers using pattern matching and constraint propagation.
Installation
pip install cryptograms
Usage
Python API
from cryptograms import solve_cryptogram, encrypt_cryptogram
# Solve a cipher
solution = solve_cryptogram("Ebiil tloia")
print(solution.plaintext) # Hello world
print(solution.confidence) # 0.95
# Encrypt plaintext (useful for generating puzzles)
ciphertext = encrypt_cryptogram("Hello world")
print(ciphertext) # e.g. Ebiil tloia
Command line
# Decrypt — accepts a string or a file path
cryptograms decrypt "Ebiil tloia"
cryptograms decrypt puzzle.txt
# Encrypt
cryptograms encrypt "Hello world"
cryptograms encrypt "Hello world" --seed 42 # reproducible output
How it works
The solver uses word-pattern matching and constraint propagation rather than frequency analysis:
- Each cipher word is encoded as a numeric pattern —
"KHOOR"→"12334" - Candidate plaintext words are looked up by pattern from a ~200k-word frequency-weighted dictionary
LetterConstraintstracks which plaintext letters each cipher letter can still map to, and propagates locks globally when a mapping is confirmed- Candidates and constraints are narrowed iteratively until every cipher word resolves to one plaintext word
- When stuck, the solver uses NLTK Brown corpus bigram/trigram frequencies to pick the most contextually likely candidate and continues
Data
Word frequencies from wordfreq. Bigram and trigram context from the NLTK Brown corpus, downloaded automatically on first use.
Web interface
A self-hostable web interface is available in the repository. Run it with:
pip install cryptograms[web]
uvicorn cryptograms.api:app
Metadata
Release files for cryptograms 0.1.0
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 |
|---|---|---|---|---|
| cryptograms-0.1.0.tar.gz | 24.3 kB | Without provenance | Details for cryptograms-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cryptograms-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for cryptograms-0.1.0-py3-none-any.whl |
Total release size: 43.5 kB
Release files / cryptograms-0.1.0.tar.gz
| Download URL | cryptograms-0.1.0.tar.gz |
|---|---|
| Size | 24.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5fd4f1fcc7cea1e1e606d85c7b34a1af097fe9e14084be4838bfb49b1f986de0
|
|
BLAKE2b-256 checksum How to use checksums |
706c1cbde4368fcabf0e245f7903b6ed4b743d8a2292eebcc157e772e1e32aef
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.2
|
Release files / cryptograms-0.1.0-py3-none-any.whl
| Download URL | cryptograms-0.1.0-py3-none-any.whl |
|---|---|
| Size | 19.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9aaabe6809b518901d26ce4492b472222df43f732bf603b7b96182e71253540b
|
|
BLAKE2b-256 checksum How to use checksums |
d3ebb0f357c4b97ebef3168f4564d7bcd8f0b7d80debe35a4e21df8dbf43492a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.2
|
Security for cryptograms 0.1.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.