Metadata-Version: 2.1
Name: basen-encoder
Version: 1.0.2
Summary: Custom encoder that encodes any binary data to given alphabet.
Keywords: generator base-encoder basen base base128 base64 base32 base16
Home-page: https://github.com/vd2org/basen
Author-Email: vd <basen@vd2.org>
License: MIT License
        
        Copyright (c) 2017-2024 Vd
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Education
Classifier: Intended Audience :: Information Technology
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Topic :: Utilities
Classifier: Topic :: Software Development
Classifier: Topic :: Software Development :: Libraries
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Project-URL: Homepage, https://github.com/vd2org/basen
Project-URL: Repository, https://github.com/vd2org/basen.git
Project-URL: Issues, https://github.com/vd2org/basen/issues
Requires-Python: <3.13,>=3.8
Description-Content-Type: text/markdown

# 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 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:

```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 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:

```text
10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
Am851IcwtXApqVErDmkjfH9ikry1v4YsyaP4zUrrmM8H8j83wfxbV02K
10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
```

### Encode a binary

Encode a binary data to printable text like base64 but with an arbitrary alphabet.

```python
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:

```text
Some binary data...
aMUkfaVgYAaXhpLbbsxuaUOUCaTprkavVgx==
bytearray(b'Some binary data...')
```
