Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vd2org/basen
Custom encoder that encodes any binary data to given alphabet.
https://github.com/vd2org/basen
base base-encoder base128 base16 base32 base64 basen generator
Last synced: 24 days ago
JSON representation
Custom encoder that encodes any binary data to given alphabet.
- Host: GitHub
- URL: https://github.com/vd2org/basen
- Owner: vd2org
- License: mit
- Created: 2019-03-28T11:49:55.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-02-26T22:43:16.000Z (9 months ago)
- Last Synced: 2024-10-03T15:36:44.968Z (about 1 month ago)
- Topics: base, base-encoder, base128, base16, base32, base64, basen, generator
- Language: Python
- Homepage:
- Size: 137 KB
- Stars: 3
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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
```python
import stringimport 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:```text
1000 qi 1000
1009 qr 1009
1018 qA 1018
1027 qJ 1027
...
```### Huge numbers
Even huge numbers can be encoded as well.
```python
import stringimport 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:
```text
10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
Am851IcwtXApqVErDmkjfH9ikry1v4YsyaP4zUrrmM8H8j83wfxbV02K
10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
```### Encode a binary
Encode a binary data to printable text like base64 but with an arbitrary alphabet.
```python
import stringimport 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:
```text
Some binary data...
aMUkfaVgYAaXhpLbbsxuaUOUCaTprkavVgx==
bytearray(b'Some binary data...')
```