# baseAnything
## What
A library for encoding integers into a series of symbols. The symbols can be anything.
And it decodes too, of course.
## Testing
Run `test.py`.
## Howto
Install it (eg `pip install baseAnything`), and then `from baseAnything import baseX`.
Examples, from the doctests:
#### Basic use
```
>>> bxbinary = baseX('01') # Instantiates a baseX object with a Base-2 aka binary string-symbol alphabet
>>> bxbinary % 7
'111'
```
#### Proof: A roundtrip
```
>>> bxhexadecimal = baseX('0123456789ABCDEF') # Base-16 aka hexadecimal
>>> 9000 == int(bxhexadecimal % 9000, base=16)
True
```
#### Arbitrary symbols
One can use arbitrary symbols. Anything. `['bla', 2, object(), object()]` is a valid symbol alphabet.
It may be desirable to get a symbol list back rather than a string, so that the symbol framing is kept
intact — because, for instance, a symbol alphabet of `['a', 'aa']` yields ambiguity in its output when it's
mashed into a string; `'aaa'` has 3 possible interpretations.
The `%` operator yields strings when encoding an integer.
The `/` operator makes a baseX object return the encoding as a list of symbols instead.
```
>>> bxfunky = baseX(['Do', 'Re', 'Mi', 'Fa', 'Sol', 'La', 'Ti'])
>>> bxfunky % 10 # Emits a warning, because the result may not be decodable!
'ReFa'
>>> bxfunky / 10 # Symbols returned as a list rather than concatenated into a string.
['Re', 'Fa']
>>> 10 == bxfunky / (bxfunky / 10)
True
```
#### Bizarre encodings
Speaking of arbitrary symbols... how about this visually compact encoding:
```
>>> bxbizarre = baseX(list(map(chr, range(0x0300, 0x036f)))) # unicode diacritical marks
>>> wut = 'O' + bxbizarre % 1234567890
>>> wut
'Ơ̡͎̈̎'
>>> bxbizarre / wut[1:]
1234567890
```
## I don't like the operator overloading interface
Then use `baseX.decode(input: Sequence)` and `baseX.encode(num: int)`.
## Bugs
There are problems when using large numbers.
```
>>> base22 = baseX(list(range(22)))
>>> largenumber = (base22 / base22.alphabet) # that's 774212873841767703847271481
>>> base22 / (base22 / largenumber) == largenumber
False # But it should be true.
```
Raw data
{
"_id": null,
"home_page": "https://git.sr.ht/~nullenenenen/baseAnything/",
"name": "baseAnything",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": null,
"author": "nullenenenen",
"author_email": "nullenenenen@gavagai.eu",
"download_url": "https://files.pythonhosted.org/packages/06/30/e3c3aecbae0d9d7e02f638ac15f969671119c5880528e0fdf40014e85af4/baseAnything-0.1.0.tar.gz",
"platform": null,
"description": "# baseAnything\n\n## What\n\nA library for encoding integers into a series of symbols. The symbols can be anything.\nAnd it decodes too, of course.\n\n## Testing\n\nRun `test.py`.\n\n## Howto\n\nInstall it (eg `pip install baseAnything`), and then `from baseAnything import baseX`.\nExamples, from the doctests:\n\n#### Basic use\n```\n>>> bxbinary = baseX('01') # Instantiates a baseX object with a Base-2 aka binary string-symbol alphabet\n>>> bxbinary % 7\n'111'\n\n```\n\n#### Proof: A roundtrip\n```\n>>> bxhexadecimal = baseX('0123456789ABCDEF') # Base-16 aka hexadecimal\n>>> 9000 == int(bxhexadecimal % 9000, base=16)\nTrue\n\n```\n\n#### Arbitrary symbols\nOne can use arbitrary symbols. Anything. `['bla', 2, object(), object()]` is a valid symbol alphabet.\n\nIt may be desirable to get a symbol list back rather than a string, so that the symbol framing is kept\nintact \u2014 because, for instance, a symbol alphabet of `['a', 'aa']` yields ambiguity in its output when it's\nmashed into a string; `'aaa'` has 3 possible interpretations.\n\nThe `%` operator yields strings when encoding an integer.\nThe `/` operator makes a baseX object return the encoding as a list of symbols instead.\n\n```\n>>> bxfunky = baseX(['Do', 'Re', 'Mi', 'Fa', 'Sol', 'La', 'Ti'])\n>>> bxfunky % 10 # Emits a warning, because the result may not be decodable!\n'ReFa'\n>>> bxfunky / 10 # Symbols returned as a list rather than concatenated into a string.\n['Re', 'Fa']\n>>> 10 == bxfunky / (bxfunky / 10)\nTrue\n\n```\n\n#### Bizarre encodings\nSpeaking of arbitrary symbols... how about this visually compact encoding:\n\n```\n>>> bxbizarre = baseX(list(map(chr, range(0x0300, 0x036f)))) # unicode diacritical marks\n>>> wut = 'O' + bxbizarre % 1234567890\n>>> wut\n'O\u0308\u030e\u034e\u0321\u031b'\n>>> bxbizarre / wut[1:]\n1234567890\n\n```\n\n## I don't like the operator overloading interface\nThen use `baseX.decode(input: Sequence)` and `baseX.encode(num: int)`.\n\n\n## Bugs\nThere are problems when using large numbers.\n\n```\n>>> base22 = baseX(list(range(22)))\n>>> largenumber = (base22 / base22.alphabet) # that's 774212873841767703847271481\n>>> base22 / (base22 / largenumber) == largenumber\nFalse # But it should be true.\n```\n",
"bugtrack_url": null,
"license": "MPL-2.0",
"summary": "baseAnything - encode/decode any integer into/from a series of symbols of a custom palette.",
"version": "0.1.0",
"project_urls": {
"Documentation": "https://git.sr.ht/~nullenenenen/baseAnything/tree/master/item/README.md",
"Homepage": "https://git.sr.ht/~nullenenenen/baseAnything/",
"Source": "https://git.sr.ht/~nullenenenen/baseAnything/"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "34b3a5f1025d3f456a8ff7adaf0b6ce4e3a453c7ceee83037f641a4930ba18de",
"md5": "cd0b4d0b6758e624aa97218f1ea6159c",
"sha256": "f250fc873ccd679b69f6ceb691bd9e0e26bbcacf9cc36074d183ea8a386a158a"
},
"downloads": -1,
"filename": "baseAnything-0.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "cd0b4d0b6758e624aa97218f1ea6159c",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 10008,
"upload_time": "2024-03-19T22:24:56",
"upload_time_iso_8601": "2024-03-19T22:24:56.304638Z",
"url": "https://files.pythonhosted.org/packages/34/b3/a5f1025d3f456a8ff7adaf0b6ce4e3a453c7ceee83037f641a4930ba18de/baseAnything-0.1.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "0630e3c3aecbae0d9d7e02f638ac15f969671119c5880528e0fdf40014e85af4",
"md5": "0a3f39a54fb9f87a819c697c72aa4444",
"sha256": "e50f3aed4a3dddb3957933df508effd66141709299c807ea16dab16f4c2bf562"
},
"downloads": -1,
"filename": "baseAnything-0.1.0.tar.gz",
"has_sig": false,
"md5_digest": "0a3f39a54fb9f87a819c697c72aa4444",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 8877,
"upload_time": "2024-03-19T22:24:59",
"upload_time_iso_8601": "2024-03-19T22:24:59.323463Z",
"url": "https://files.pythonhosted.org/packages/06/30/e3c3aecbae0d9d7e02f638ac15f969671119c5880528e0fdf40014e85af4/baseAnything-0.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-03-19 22:24:59",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "baseanything"
}