Lossless, pronounceable, encrypted codec for any identifier — reversible, format-preserving, human-readable
Project description
HCE
Lossless, pronounceable, encrypted codec for any identifier — reversible, format-preserving, human-readable.
Install
pip install hce
Quick Start
import hce
h = hce.Hce(
key=b"32-byte-secret-key-here-xxxxxx!!",
level="universal",
mode="sealed",
)
encoded = h.encode(bytes(range(16)))
decoded = h.decode(encoded)
print(decoded.hex())
API
Constructor
hce.Hce(
key: bytes | None = None,
level: str = "universal",
mode: str = "sealed",
bit_width: int = 128,
) -> Hce
| Param | Type | Description |
|---|---|---|
key |
bytes | None |
Encryption key bytes. None for plain mode. |
level |
str |
"universal", "eu", "en", "numeric" |
mode |
str |
"sealed", "open", "plain" |
bit_width |
int |
16–128. Default 128. |
Core Methods
h.encode(data: bytes) -> str
h.decode(input: str) -> bytes
h.recover(input: str) -> bytes
| Method | Description |
|---|---|
encode(data) |
Encrypt + encode bytes to HCE string. |
decode(input) |
Decode + decrypt HCE string to bytes. Raises ValueError on integrity failure. |
recover(input) |
Attempt self-recovery on corrupted input. Returns recovered bytes or raises ValueError. |
Domain Configuration
h.with_bit_width(bits: int) -> Hce
h.with_modulus(modulus: int) -> Hce
h.with_cipher(kind: str, key: bytes | None = None) -> Hce
| Method | Description |
|---|---|
with_bit_width(bits) |
Set cipher domain bit width (16-128). |
with_modulus(n) |
Set modulus domain. Must be ≥ 2. |
with_cipher(kind, key?) |
Select cipher: "feistel" (default, 8-round HMAC-SHA256) or "shuffle" (4-round lightweight). |
Output Configuration
h.with_case("upper" | "lower") -> Hce
h.with_check_syllables(n: int) -> Hce
h.with_separator(sep: str) -> Hce
| Method | Description |
|---|---|
with_case(case) |
Output case. Default "upper". |
with_check_syllables(n) |
Number of HMAC check syllables (1-8). Default 1. |
with_separator(sep) |
Chunk separator character. Default "-". |
Chunking
h.with_chunk_none() -> Hce
h.with_chunk_fixed(char_size: int) -> Hce
h.with_chunk_pattern(pattern: list[int]) -> Hce
| Method | Description |
|---|---|
with_chunk_none() |
No separators. |
with_chunk_fixed(n) |
Chunk every n characters. |
with_chunk_pattern([3,3,4,4]) |
Custom syllable-per-chunk pattern. |
Timestamp
h.with_timestamp_config(epoch_ms: int, granularity: str) -> Hce
| Param | Description |
|---|---|
epoch_ms |
Unix epoch in milliseconds. |
granularity |
"second" | "minute" | "hour" | "day" | "week" | "month" |
Levels
Each level uses a different phoneme set:
| Level | Onset | Vowel+Nucleus | Description |
|---|---|---|---|
universal |
29 | 20 | Cross-lingual, PHOIBLE 40% threshold |
eu |
27 | 20 | European languages |
en |
24 | 18 | English-specific |
numeric |
10 | 5 | Numeric-style (0-9 mapped to phonemes) |
Modes
| Mode | Check | Purpose |
|---|---|---|
sealed |
HMAC-SHA256 | Full confidentiality + integrity |
open |
HMAC-SHA256 | Timestamp prefix for sorting |
plain |
CRC | No encryption, CRC integrity only |
Development
cd crates/hce-py
python -m venv .venv
source .venv/bin/activate
pip install maturin pytest
maturin develop
pytest tests/
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hce-0.1.0-cp312-cp312-win_amd64.whl.
File metadata
- Download URL: hce-0.1.0-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 128.9 kB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.14.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
944c9714777066c6bfbae789071aabff8e2b1f2864b2f088a9e8fd53d0c02369
|
|
| MD5 |
89d7e977b7c9569b5d4b26686aeb9b46
|
|
| BLAKE2b-256 |
cdd8618d2d755bf3e7aef7a3b380117cb5f780105f0396e68a89b46efb9c2b54
|
File details
Details for the file hce-0.1.0-cp312-cp312-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: hce-0.1.0-cp312-cp312-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 223.4 kB
- Tags: CPython 3.12, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.14.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9be2f46fea2e9beb75fe6c69b3ed1cdd568ec018dbe234565a171f67dd65f690
|
|
| MD5 |
64b0a97b6e93673194bf085609245768
|
|
| BLAKE2b-256 |
24e67b8ce8f378af1752cad05f3b14fd7c69474f107b9595f4afdaafcf476a0d
|
File details
Details for the file hce-0.1.0-cp312-cp312-macosx_11_0_arm64.whl.
File metadata
- Download URL: hce-0.1.0-cp312-cp312-macosx_11_0_arm64.whl
- Upload date:
- Size: 194.0 kB
- Tags: CPython 3.12, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.14.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2aaa9aaaa13eba31addf87a66f59c4202fce70ed406c07e7bedfe8bc7acc196f
|
|
| MD5 |
6f8f22b7ad794aed834ae519134224c8
|
|
| BLAKE2b-256 |
d770a70c43a35614aa6c7b093c2cf46f36fe411061ac7fae4b689cb0ee598584
|