BaseN
Custom encoder that encodes any binary data to given alphabet.
Requirements
Python 3.8 and above. No additional dependencies.
Installation
pip install basen-encoder
Usage
Numbers
Encode a number to the string and back
import string
import basen
ALPHABET = string.ascii_letters + string.digits
for i in range(1000, 2000, 9):
encoded = basen.int2base(i, ALPHABET)
decoded = basen.base2int(encoded, ALPHABET)
print(i, encoded, decoded)
Output:
1000 qi 1000
1009 qr 1009
1018 qA 1018
1027 qJ 1027
...
Huge numbers
Even huge numbers can be encoded as well.
import string
import basen
ALPHABET = string.ascii_letters + string.digits
NUM = 10**100
encoded = basen.int2base(i, ALPHABET)
decoded = basen.base2int(encoded, ALPHABET)
print(NUM)
print(encoded)
print(decoded)
Output:
10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
Am851IcwtXApqVErDmkjfH9ikry1v4YsyaP4zUrrmM8H8j83wfxbV02K
10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
Encode a binary
Encode a binary data to printable text like base64 but with an arbitrary alphabet.
import string
import basen
ALPHABET = string.ascii_letters
DATA = "Some binary data..."
encoder = basen.BaseN(string.ascii_letters, 3)
encoded = encoder.encode(DATA)
decoded = encoder.decode(encoded)
print(DATA)
print(encoded)
print(decoded)
Output:
Some binary data...
aMUkfaVgYAaXhpLbbsxuaUOUCaTprkavVgx==
bytearray(b'Some binary data...')
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
basen_encoder-1.0.2.tar.gz
(103.8 kB
view details)
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 basen_encoder-1.0.2.tar.gz.
File metadata
- Download URL: basen_encoder-1.0.2.tar.gz
- Upload date:
- Size: 103.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
pdm/2.12.4 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7e44f5b50aa134ea5136314def9da85b52c06c6bcdcc9a4a916a7e7d991e6003
|
|
| MD5 |
73a8c0ad9495cb0a87c5670a81ea3fce
|
|
| BLAKE2b-256 |
b0053e78bed3d03f8ea7313a7e0515bf00a096dca841a41ccc1eb358785eea63
|
File details
Details for the file basen_encoder-1.0.2-py3-none-any.whl.
File metadata
- Download URL: basen_encoder-1.0.2-py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
pdm/2.12.4 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
76c57def490bae3da454b6ca16b83d41bd10cfe63f0d871119ef539337e17399
|
|
| MD5 |
40d6aa5d48e7cff6ed3265bc5f370581
|
|
| BLAKE2b-256 |
b8aec4dfc9a07bcfe540e397602dd669d82e0d7ad3d597edf0e7815a52361ebb
|