Skip to main content

pybased

Library for creating arbitrary binary encodings. Includes variations on base32, base64, base85, and more.

WARNING: Although these encodings do work end-to-end, they are not compatible with traditional implementations!

I am working on finding out why.

Encodings

Types

  • Sliding: Random-access bitwise implementation, theoretically compatible with bytestrings of arbitrary size.
  • BigInt: Converts bytes into large integers, then incrementally divides by the radix. Incompatible with large files. Suitable for hashes and shorter bytestrings.
  • Biterator: Iterates through each byte from the input stream and adds it to a buffer, then extracts the required number of bits to convert to the other radix. Based roughly off of CPython's base64 encoder, but heavily modified to enable arbitrary conversions. WIP.

Available Encodings

Supported Encodings
IDTypeBits/CharChars/ByteAlphabet
base32Biterator55ABCDEFGHIJKLMNOPQRSTUVWXYZ234567
base32hexBiterator550123456789ABCDEFGHIJKLMNOPQRSTUV
base46BigIntN/AN/AABCDEFGHJKMNPQRSTUVWXYZabcdefghjkmnpqrstuvwxyz
base62BigIntN/AN/A0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
base64Biterator63ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/
base64b64Biterator63./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
base64bashBiterator630123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@_
base64bcryptBiterator63./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789
base64hqxBiterator63!"#$%&'()*+,-012345689@ABCDEFGHIJKLMNPQRSTUVXYZ[`abcdefhijklmpqr
base64urlBiterator63ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_
base64uuBiterator63 !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_
base64xxBiterator63+-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
base85Biterator77ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!#$%&()*+-;<=>?@^_`{|}~
base94BigIntN/AN/A!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
crockford32Biterator550123456789ABCDEFGHJKMNPQRSTVWXYZ
geohash32Biterator550123456789bcdefghjkmnpqrstuvwxyz
nintendo32Biterator550123456789BCDFGHJKLMNPQRSTVWXYZ?
wordsafe32Biterator5523456789CFGHJMPQRVWXcfghjmpqrvwx
zbase32Biterator55ybndrfg8ejkmcpqxot1uwisza345h769

Status

Supported Encodings
StandardEncodedDecodedPassed Test
base32JBSWY3DPFQQHO33SNRSCC===b'Hello, world!'✔
base32hex91IMOR3F5GG7ERRIDHI22===b'Hello, world!'✔
base46GnNaagudEKYvFzFrZSSb'Hello, world!'✔
base621wJfrzvdbthTq5ANZBb'Hello, world!'✔
base64SGVsbG8sIHdvcmxkIQ==b'Hello, world!'✔
base64b64G4JgP4wg65RjQalY6E==b'Hello, world!'✔
base64bashi6lIr6YI87tLsCNA8g==b'Hello, world!'✔
base64bcryptQETqZE6qGFbtakviGO==b'Hello, world!'✔
base64hqx5'9XE'mX)(G[FQaN)3==b'Hello, world!'✔
base64urlSGVsbG8sIHdvcmxkIQ==b'Hello, world!'✔
base64uu2&5L;&\\L('=O<FQD(0b'Hello, world!'✔
base64xxG4JgP4wg65RjQalY6E==b'Hello, world!'✔
base85ERRERR❌
base94/P\|?l:+>Nq\\sr<+rb'Hello, world!'✔
crockford3291JPRV3F5GG7EVVJDHJ22b'Hello, world!'✔
geohash3291kqsv3g5hh7fvvkejk22b'Hello, world!'✔
nintendo3291LQSW3H5JJ7GWWLFKL22b'Hello, world!'✔
wordsafe32F3Wgjq5Q7RR9PqqWMVW44b'Hello, world!'✔
zbase32jb1sa5dxfoo8q551pt1nnb'Hello, world!'✔
Errors:
base85: c = 99, len = 85, bpc = 7

Getting started

$ pip install pybased

Doing stuff

# Lets's assume we want to use the Crockford32 encoding scheme.
from based.standards.base32 import crockford32

# And let's assume the variable data has what we want to encode.
data: bytes = ...

# Encode to string.
encoded: str = crockford32.encode_bytes(data)

# ...

# Decode the string back to bytes.
data: bytes = crockford32.decode_bytes(encoded)

based Command-Line Tool

$ based --help
usage: based [-h] {dump,encode,decode} ...

positional arguments:
  {dump,encode,decode}

optional arguments:
  -h, --help            show this help message and exit

NOTE: The based CLI tool is currently only useful for testing, and is under very active development.

Encode string to Base94

$ based encode --standard=base94 --input-string 'Hello, world!'
/P|?l:+>Nq\sr<+r

Encode string to Base94 and output JSON

$ based encode --standard=base94 --input-string 'Hello, world!' --output-format json
{"encoded": "/P|?l:+>Nq\\sr<+r"}

Decode data from Base94

$ based decode --standard=base94 --input-string '/P|?l:+>Nq\sr<+r'
>>> input chars: 16B
Bytes representation: b'Hello, world!'
Hex representation: 48656c6c6f2c20776f726c6421

Various Output Encoding Formats

$ based decode --standard=base94 --input-string '/P|?l:+>Nq\sr<+r' --output-format json
>>> input chars: 16B
{"b64": "SGVsbG8sIHdvcmxkIQ==", "utf-8": "Hello, world!"}
$ based decode --standard=base94 --input-string '/P|?l:+>Nq\sr<+r' --output-format yaml
>>> input chars: 16B
encoded: !!binary |
  SGVsbG8sIHdvcmxkIQ==

Metadata

Release files for pybased 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pybased 0.0.2
File Size Uploaded Provenance
pybased-0.0.2.tar.gz 16.6 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for pybased 0.0.2
File Interpreter ABI Platform
pybased-0.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 36.9 kB

Release files / pybased-0.0.2.tar.gz

Download URL pybased-0.0.2.tar.gz
Size 16.6 kB
Tags Source
SHA-256 checksum
How to use checksums
8ba07a073cec9f33207f2e4b99279b864d284b20f6bf18df933d84b2d520d0cf
BLAKE2b-256 checksum
How to use checksums
c977dd461e9d50531d6f9f4ea3f6ff5a2acf7d38eeafb59071422fb5a8a324d1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.8.10

Release files / pybased-0.0.2-py3-none-any.whl

Download URL pybased-0.0.2-py3-none-any.whl
Size 20.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dca1f212c41e5720c56c858575f502b39ea132810ef12f5c2c354edd6faae34b
BLAKE2b-256 checksum
How to use checksums
b32752fb7875822bac8ff9396bb95f69d152f512466c4d68cca635eb740a31b8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.8.10

Security for pybased 0.0.2

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.

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page