basen-encoder


Namebasen-encoder JSON
Version 1.0.2 PyPI version JSON
download
home_pagehttps://github.com/vd2org/basen
SummaryCustom encoder that encodes any binary data to given alphabet.
upload_time2024-02-26 22:43:45
maintainer
docs_urlNone
author
requires_python<3.13,>=3.8
licenseMIT 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.
keywords generator base-encoder basen base base128 base64 base32 base16
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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...')
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/vd2org/basen",
    "name": "basen-encoder",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "<3.13,>=3.8",
    "maintainer_email": "",
    "keywords": "generator base-encoder basen base base128 base64 base32 base16",
    "author": "",
    "author_email": "vd <basen@vd2.org>",
    "download_url": "https://files.pythonhosted.org/packages/b0/05/3e78bed3d03f8ea7313a7e0515bf00a096dca841a41ccc1eb358785eea63/basen_encoder-1.0.2.tar.gz",
    "platform": null,
    "description": "# BaseN\n\nCustom encoder that encodes any binary data to given alphabet.\n\n### Requirements\n\nPython 3.8 and above. No additional dependencies.\n\n### Installation\n\n`pip install basen-encoder`\n\n## Usage\n\n### Numbers\n\nEncode a number to the string and back\n\n```python\nimport string\n\nimport basen\n\nALPHABET = string.ascii_letters + string.digits\n\nfor i in range(1000, 2000, 9):\n    encoded = basen.int2base(i, ALPHABET)\n    decoded = basen.base2int(encoded, ALPHABET)\n\n    print(i, encoded, decoded)\n```\n#### Output:\n\n```text\n1000 qi 1000\n1009 qr 1009\n1018 qA 1018\n1027 qJ 1027\n...\n```\n\n### Huge numbers\n\nEven huge numbers can be encoded as well.\n\n```python\nimport string\n\nimport basen\n\nALPHABET = string.ascii_letters + string.digits\n\nNUM = 10**100\n\nencoded = basen.int2base(i, ALPHABET)\ndecoded = basen.base2int(encoded, ALPHABET)\n\nprint(NUM)\nprint(encoded)\nprint(decoded)\n```\n\n#### Output:\n\n```text\n10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\nAm851IcwtXApqVErDmkjfH9ikry1v4YsyaP4zUrrmM8H8j83wfxbV02K\n10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n```\n\n### Encode a binary\n\nEncode a binary data to printable text like base64 but with an arbitrary alphabet.\n\n```python\nimport string\n\nimport basen\n\nALPHABET = string.ascii_letters\nDATA = \"Some binary data...\"\n\nencoder = basen.BaseN(string.ascii_letters, 3)\nencoded = encoder.encode(DATA)\ndecoded = encoder.decode(encoded)\n\nprint(DATA)\nprint(encoded)\nprint(decoded)\n```\n\n#### Output:\n\n```text\nSome binary data...\naMUkfaVgYAaXhpLbbsxuaUOUCaTprkavVgx==\nbytearray(b'Some binary data...')\n```\n",
    "bugtrack_url": null,
    "license": "MIT License\n        \n        Copyright (c) 2017-2024 Vd\n        \n        Permission is hereby granted, free of charge, to any person obtaining a copy\n        of this software and associated documentation files (the \"Software\"), to deal\n        in the Software without restriction, including without limitation the rights\n        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n        copies of the Software, and to permit persons to whom the Software is\n        furnished to do so, subject to the following conditions:\n        \n        The above copyright notice and this permission notice shall be included in all\n        copies or substantial portions of the Software.\n        \n        THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n        SOFTWARE.",
    "summary": "Custom encoder that encodes any binary data to given alphabet.",
    "version": "1.0.2",
    "project_urls": {
        "Homepage": "https://github.com/vd2org/basen",
        "Issues": "https://github.com/vd2org/basen/issues",
        "Repository": "https://github.com/vd2org/basen.git"
    },
    "split_keywords": [
        "generator",
        "base-encoder",
        "basen",
        "base",
        "base128",
        "base64",
        "base32",
        "base16"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b8aec4dfc9a07bcfe540e397602dd669d82e0d7ad3d597edf0e7815a52361ebb",
                "md5": "40d6aa5d48e7cff6ed3265bc5f370581",
                "sha256": "76c57def490bae3da454b6ca16b83d41bd10cfe63f0d871119ef539337e17399"
            },
            "downloads": -1,
            "filename": "basen_encoder-1.0.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "40d6aa5d48e7cff6ed3265bc5f370581",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<3.13,>=3.8",
            "size": 5612,
            "upload_time": "2024-02-26T22:43:43",
            "upload_time_iso_8601": "2024-02-26T22:43:43.663593Z",
            "url": "https://files.pythonhosted.org/packages/b8/ae/c4dfc9a07bcfe540e397602dd669d82e0d7ad3d597edf0e7815a52361ebb/basen_encoder-1.0.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b0053e78bed3d03f8ea7313a7e0515bf00a096dca841a41ccc1eb358785eea63",
                "md5": "73a8c0ad9495cb0a87c5670a81ea3fce",
                "sha256": "7e44f5b50aa134ea5136314def9da85b52c06c6bcdcc9a4a916a7e7d991e6003"
            },
            "downloads": -1,
            "filename": "basen_encoder-1.0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "73a8c0ad9495cb0a87c5670a81ea3fce",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<3.13,>=3.8",
            "size": 103803,
            "upload_time": "2024-02-26T22:43:45",
            "upload_time_iso_8601": "2024-02-26T22:43:45.619464Z",
            "url": "https://files.pythonhosted.org/packages/b0/05/3e78bed3d03f8ea7313a7e0515bf00a096dca841a41ccc1eb358785eea63/basen_encoder-1.0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-26 22:43:45",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "vd2org",
    "github_project": "basen",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "basen-encoder"
}
        
Elapsed time: 0.19920s