Library for creating arbitrary binary encodings. Includes variations on base32, base64, base85, and more.
Project description
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
ID | Type | Bits/Char | Chars/Byte | Alphabet |
---|---|---|---|---|
base32 | Biterator | 5 | 5 | ABCDEFGHIJKLMNOPQRSTUVWXYZ234567 |
base32hex | Biterator | 5 | 5 | 0123456789ABCDEFGHIJKLMNOPQRSTUV |
base46 | BigInt | N/A | N/A | ABCDEFGHJKMNPQRSTUVWXYZabcdefghjkmnpqrstuvwxyz |
base62 | BigInt | N/A | N/A | 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz |
base64 | Biterator | 6 | 3 | ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/ |
base64b64 | Biterator | 6 | 3 | ./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz |
base64bash | Biterator | 6 | 3 | 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@_ |
base64bcrypt | Biterator | 6 | 3 | ./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 |
base64hqx | Biterator | 6 | 3 | !"#$%&'()*+,-012345689@ABCDEFGHIJKLMNPQRSTUVXYZ[`abcdefhijklmpqr |
base64url | Biterator | 6 | 3 | ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_ |
base64uu | Biterator | 6 | 3 | !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_ |
base64xx | Biterator | 6 | 3 | +-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz |
base85 | Biterator | 7 | 7 | ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!#$%&()*+-;<=>?@^_`{|}~ |
base94 | BigInt | N/A | N/A | !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ |
crockford32 | Biterator | 5 | 5 | 0123456789ABCDEFGHJKMNPQRSTVWXYZ |
geohash32 | Biterator | 5 | 5 | 0123456789bcdefghjkmnpqrstuvwxyz |
nintendo32 | Biterator | 5 | 5 | 0123456789BCDFGHJKLMNPQRSTVWXYZ? |
wordsafe32 | Biterator | 5 | 5 | 23456789CFGHJMPQRVWXcfghjmpqrvwx |
zbase32 | Biterator | 5 | 5 | ybndrfg8ejkmcpqxot1uwisza345h769 |
Status
Standard | Encoded | Decoded | Passed Test |
---|---|---|---|
base32 | JBSWY3DPFQQHO33SNRSCC=== | b'Hello, world!' | ✔ |
base32hex | 91IMOR3F5GG7ERRIDHI22=== | b'Hello, world!' | ✔ |
base46 | GnNaagudEKYvFzFrZSS | b'Hello, world!' | ✔ |
base62 | 1wJfrzvdbthTq5ANZB | b'Hello, world!' | ✔ |
base64 | SGVsbG8sIHdvcmxkIQ== | b'Hello, world!' | ✔ |
base64b64 | G4JgP4wg65RjQalY6E== | b'Hello, world!' | ✔ |
base64bash | i6lIr6YI87tLsCNA8g== | b'Hello, world!' | ✔ |
base64bcrypt | QETqZE6qGFbtakviGO== | b'Hello, world!' | ✔ |
base64hqx | 5'9XE'mX)(G[FQaN)3== | b'Hello, world!' | ✔ |
base64url | SGVsbG8sIHdvcmxkIQ== | b'Hello, world!' | ✔ |
base64uu | 2&5L;&\\L('=O<FQD(0 | b'Hello, world!' | ✔ |
base64xx | G4JgP4wg65RjQalY6E== | b'Hello, world!' | ✔ |
base85 | ERR | ERR | ❌ |
base94 | /P\|?l:+>Nq\\sr<+r | b'Hello, world!' | ✔ |
crockford32 | 91JPRV3F5GG7EVVJDHJ22 | b'Hello, world!' | ✔ |
geohash32 | 91kqsv3g5hh7fvvkejk22 | b'Hello, world!' | ✔ |
nintendo32 | 91LQSW3H5JJ7GWWLFKL22 | b'Hello, world!' | ✔ |
wordsafe32 | F3Wgjq5Q7RR9PqqWMVW44 | b'Hello, world!' | ✔ |
zbase32 | jb1sa5dxfoo8q551pt1nn | b'Hello, world!' | ✔ |
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==
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
pybased-0.0.2.tar.gz
(16.6 kB
view details)
Built Distribution
pybased-0.0.2-py3-none-any.whl
(20.3 kB
view details)
File details
Details for the file pybased-0.0.2.tar.gz
.
File metadata
- Download URL: pybased-0.0.2.tar.gz
- Upload date:
- Size: 16.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8ba07a073cec9f33207f2e4b99279b864d284b20f6bf18df933d84b2d520d0cf |
|
MD5 | 14d80b10429e4df889ab0399c0117d10 |
|
BLAKE2b-256 | c977dd461e9d50531d6f9f4ea3f6ff5a2acf7d38eeafb59071422fb5a8a324d1 |
File details
Details for the file pybased-0.0.2-py3-none-any.whl
.
File metadata
- Download URL: pybased-0.0.2-py3-none-any.whl
- Upload date:
- Size: 20.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dca1f212c41e5720c56c858575f502b39ea132810ef12f5c2c354edd6faae34b |
|
MD5 | 954f2f63f77510e2803fcaccc16bf7b5 |
|
BLAKE2b-256 | b32752fb7875822bac8ff9396bb95f69d152f512466c4d68cca635eb740a31b8 |