Base2048 encoder/decoder — compatible with qntm/base2048
Project description
base2048
A Python implementation of Base2048 — a binary-to-text encoding that stores 11 bits per Unicode character, producing roughly 25% fewer characters than Base64.
Output is fully compatible with qntm/base2048 (the canonical JavaScript implementation). The same alphabet, the same padding scheme, the same reference test vectors.
from base2048 import encode, decode, decode_str
encode(bytes([1, 2, 4, 8, 16, 32, 64, 128])) # → 'GƸOʜeҩ'
encode("Hello, World!") # → 'ԋϠɲణరϢఋԵړƶ'
decode("ԋϠɲణరϢఋԵړƶ") # → b'Hello, World!'
decode_str("ԋϠɲణరϢఋԵړƶ") # → 'Hello, World!'
Why Base2048?
Base64 encodes 6 bits per ASCII character. Base2048 encodes 11 bits per Unicode character — nearly 2× the information density. When your transport counts Unicode code points (not bytes), Base2048 wins:
| Encoding | Bits/char | Chars for 100 bytes |
|---|---|---|
| Base64 | 6 | ~136 |
| Base2048 | 11 | ~73 |
The alphabet consists of 2048 carefully selected "safe" Unicode characters — no control characters, no whitespace, no combining diacritics — designed to survive copy-paste through any Unicode-clean system.
Installation
pip install base2048
Or from source:
git clone https://github.com/benthecyberone/base2048
cd base2048
pip install .
Usage
Library
from base2048 import encode, decode, decode_str
# Encode bytes
data = b"\x00\x01\x02\xff"
encoded = encode(data) # str
decoded = decode(encoded) # bytes — identical to data
# Encode a string (UTF-8 encoded automatically)
encoded = encode("Hello!")
text = decode_str(encoded) # 'Hello!'
Command line
# Encode
base2048 encode "Hello, World!"
echo -n "Hello, World!" | base2048 encode -
# Decode
base2048 decode "ԋϠɲణరϢఋԵړƶ"
# Demo with reference vectors
base2048
Or via python -m:
python -m base2048 encode "Hello!"
python -m base2048 decode "ϙƸ٣Ρ"
API
encode(data: bytes | str) -> str
Encode bytes (or a UTF-8 string) to a Base2048 string.
decode(encoded: str) -> bytes
Decode a Base2048 string back to bytes. Raises ValueError for invalid input.
decode_str(encoded: str, encoding: str = "utf-8") -> str
Convenience wrapper: decode and interpret the result as a string.
Encoding spec
- Primary alphabet: 2048 Unicode characters, each encoding 11 bits.
- Secondary alphabet:
0–7, used only as the final character when the input's bit count is not a multiple of 11. Encodes 3 bits. - Padding: leftover bits are padded with
1-bits (not0-bits). On decode, padding bits are verified and aValueErroris raised on mismatch.
This exactly matches the qntm/base2048 specification.
Requirements
- Python 3.10+
- No dependencies
Running the tests
pip install pytest
pytest
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 Distribution
Built Distribution
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 base2048_py-1.0.0.tar.gz.
File metadata
- Download URL: base2048_py-1.0.0.tar.gz
- Upload date:
- Size: 8.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f8a6c746dca1edbcd54a2350511fb7128d87ae0e69b0a44c9f546f2bcf48b6e8
|
|
| MD5 |
f3f4281dfc3bd597be4a38f03a62a41e
|
|
| BLAKE2b-256 |
6a7d8c2776a06b98b391da65b5302b0d30d36e196f391a5595ecb8178efaa307
|
Provenance
The following attestation bundles were made for base2048_py-1.0.0.tar.gz:
Publisher:
ci.yml on BenTheCyberOne/base2048
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
base2048_py-1.0.0.tar.gz -
Subject digest:
f8a6c746dca1edbcd54a2350511fb7128d87ae0e69b0a44c9f546f2bcf48b6e8 - Sigstore transparency entry: 1721710112
- Sigstore integration time:
-
Permalink:
BenTheCyberOne/base2048@544143ba61571f0c30a38e805f1150cb539c1d04 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/BenTheCyberOne
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@544143ba61571f0c30a38e805f1150cb539c1d04 -
Trigger Event:
push
-
Statement type:
File details
Details for the file base2048_py-1.0.0-py3-none-any.whl.
File metadata
- Download URL: base2048_py-1.0.0-py3-none-any.whl
- Upload date:
- Size: 8.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d662b6ea687381fc7b7652d502be380f849dd96ef04f854f1e3694bc559fc573
|
|
| MD5 |
eaa4fef2002e4dd25678305084467e95
|
|
| BLAKE2b-256 |
d559d557929fcd42975fea0caa70912e752d0b819b3c2d89f7712ea6b50c380c
|
Provenance
The following attestation bundles were made for base2048_py-1.0.0-py3-none-any.whl:
Publisher:
ci.yml on BenTheCyberOne/base2048
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
base2048_py-1.0.0-py3-none-any.whl -
Subject digest:
d662b6ea687381fc7b7652d502be380f849dd96ef04f854f1e3694bc559fc573 - Sigstore transparency entry: 1721710270
- Sigstore integration time:
-
Permalink:
BenTheCyberOne/base2048@544143ba61571f0c30a38e805f1150cb539c1d04 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/BenTheCyberOne
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@544143ba61571f0c30a38e805f1150cb539c1d04 -
Trigger Event:
push
-
Statement type: