Skip to main content

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: 07, 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 (not 0-bits). On decode, padding bits are verified and a ValueError is 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

base2048_py-1.0.0.tar.gz (8.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

base2048_py-1.0.0-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

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

Hashes for base2048_py-1.0.0.tar.gz
Algorithm Hash digest
SHA256 f8a6c746dca1edbcd54a2350511fb7128d87ae0e69b0a44c9f546f2bcf48b6e8
MD5 f3f4281dfc3bd597be4a38f03a62a41e
BLAKE2b-256 6a7d8c2776a06b98b391da65b5302b0d30d36e196f391a5595ecb8178efaa307

See more details on using hashes here.

Provenance

The following attestation bundles were made for base2048_py-1.0.0.tar.gz:

Publisher: ci.yml on BenTheCyberOne/base2048

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for base2048_py-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d662b6ea687381fc7b7652d502be380f849dd96ef04f854f1e3694bc559fc573
MD5 eaa4fef2002e4dd25678305084467e95
BLAKE2b-256 d559d557929fcd42975fea0caa70912e752d0b819b3c2d89f7712ea6b50c380c

See more details on using hashes here.

Provenance

The following attestation bundles were made for base2048_py-1.0.0-py3-none-any.whl:

Publisher: ci.yml on BenTheCyberOne/base2048

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page