Metadata-Version: 2.1
Name: baseAnything
Version: 0.1.0
Summary: baseAnything - encode/decode any integer into/from a series of symbols of a custom palette.
Home-page: https://git.sr.ht/~nullenenenen/baseAnything/
Author: nullenenenen
Author-email: nullenenenen@gavagai.eu
License: MPL-2.0
Project-URL: Documentation, https://git.sr.ht/~nullenenenen/baseAnything/tree/master/item/README.md
Project-URL: Source, https://git.sr.ht/~nullenenenen/baseAnything/
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)
Classifier: Operating System :: OS Independent
Classifier: Topic :: Software Development :: Libraries
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE

# 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
'Ơ̡͎̈̎'
>>> 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.
```
