Skip to content

Commit 3ff5147

Browse files
committed
Refined codec: base
1 parent 134a7c6 commit 3ff5147

4 files changed

Lines changed: 23 additions & 2 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ o
171171
`atbash` | text <-> Atbash ciphertext | aka Atbash Cipher
172172
`bacon` | text <-> Bacon ciphertext | aka Baconian Cipher
173173
`barbie-N` | text <-> barbie ciphertext | aka Barbie Typewriter (N belongs to [1, 4])
174-
`baseXX` | text <-> baseXX | see [base encodings](https://python-codext.readthedocs.io/en/latest/enc/base.html)
174+
`baseXX` | text <-> baseXX | see [base encodings](https://python-codext.readthedocs.io/en/latest/enc/base.html) (incl base32, 36, 45, 58, 62, 63, 64, 91, 100, 122)
175175
`baudot` | text <-> Baudot code bits | supports CCITT-1, CCITT-2, EU/FR, ITA1, ITA2, MTK-2 (Python3 only), UK, ...
176176
`bcd` | text <-> binary coded decimal text | encodes characters from their (zero-left-padded) ordinals
177177
`braille` | text <-> braille symbols | Python 3 only

codext/base/base91.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ def encode(text, errors="strict"):
5353
else:
5454
bits += "0" * (13 - len(bits))
5555
n = int(bits, 2)
56-
print(bits, n)
5756
s += b91[n // 91] + b91[n % 91]
5857
else:
5958
for c in t:

codext/base/baseN.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@
5959
base(B62, r"^base[-_]?62(|[-_]inv(?:erted)?)$")
6060

6161

62+
B63 = {'': upper + lower + digits + "$", 'inv': lower + upper + digits + "$"}
63+
base(B63, r"^base[-_]?63(|[-_]inv(?:erted)?)$")
64+
65+
6266
B64 = {
6367
r'': upper + lower + digits + "+/",
6468
r'[-_]inv(erted)?$': lower + upper + digits + "+/",

docs/enc/base.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,12 @@ Note that for `base64`, it overwrites the native `base64_codec` to also support
6262
:---: | :---: | --- | ---
6363
`base3` | text <-> Base3 encoded text | `base[-_]?36(|[-_]inv(erted)?)` |
6464
`base36` | text <-> Base36 encoded text | `base[-_]?36(|[-_]inv(erted)?)` |
65+
`base45` | text <-> Base45 encoded text | `base[-_]?45(|[-_]inv(erted)?)` |
6566
`base58` | text <-> Base58 encoded text | `base[-_]?58(|[-_](bc|bitcoin|rp|ripple|fl|flickr|short[-]?url|url))` | supports Bitcoin, Ripple and short URL
6667
`base62` | text <-> Base62 encoded text | `base[-_]?62(|[-_]inv(erted)?)` |
68+
`base63` | text <-> Base63 encoded text | `base[-_]?63(|[-_]inv(erted)?)` |
69+
`base91` | text <-> Base91 encoded text | `base[-_]?91(|[-_]inv(erted)?)` |
70+
`base91-alt` | text <-> Alternate Base91 encoded text | `base[-_]?91[-_]alt(?:ernate)?(|[-_]inv(erted)?)` | Another version of Base91
6771

6872
```python
6973
>>> codext.encode("test", "base3")
@@ -77,6 +81,13 @@ Note that for `base64`, it overwrites the native `base64_codec` to also support
7781
'this is a test'
7882
```
7983

84+
```python
85+
>>> codext.encode("this is a test!", "base45")
86+
'AWE+EDH44.OEOCC7WE QEX0'
87+
>>> codext.decode('AWE+EDH44.OEOCC7WE QEX0', "base45")
88+
'this is a test!'
89+
```
90+
8091
```python
8192
>>> codext.encode("this is a test", "base58")
8293
'jo91waLQA1NNeBmZKUF'
@@ -93,6 +104,13 @@ Note that for `base64`, it overwrites the native `base64_codec` to also support
93104
'CsoB4HQ5gmgMyCenF7E'
94105
```
95106

107+
```python
108+
>>> codecs.encode("This is a test !", "base91")
109+
'nX,<:WRT%yxth90oZB^C'
110+
>>> codext.encode("This is a test !", "base91-alt")
111+
'?a&[jv4S3Wg>,71@Jo#K'
112+
```
113+
96114
!!! note "Generic encodings"
97115

98116
Base encodings are available for any N other than the ones explicitely specified using the "`-generic`" suffix. Their charsets consist of printable characters from the `string` module for N up to 100 and for characters composed from the 256 possible ordinals for a greater N.

0 commit comments

Comments
 (0)