base62-py 1.3.13__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- base62_py-1.3.13/LICENSE +21 -0
- base62_py-1.3.13/MANIFEST.in +2 -0
- base62_py-1.3.13/PKG-INFO +113 -0
- base62_py-1.3.13/README.md +76 -0
- base62_py-1.3.13/pyproject.toml +34 -0
- base62_py-1.3.13/setup.cfg +4 -0
- base62_py-1.3.13/src/base62/__init__.py +7 -0
- base62_py-1.3.13/src/base62/__main__.py +33 -0
- base62_py-1.3.13/src/base62/base62.py +1 -0
- base62_py-1.3.13/src/base62/decoder.py +22 -0
- base62_py-1.3.13/src/base62/encoder.py +21 -0
- base62_py-1.3.13/src/base62_py.egg-info/PKG-INFO +113 -0
- base62_py-1.3.13/src/base62_py.egg-info/SOURCES.txt +16 -0
- base62_py-1.3.13/src/base62_py.egg-info/dependency_links.txt +1 -0
- base62_py-1.3.13/src/base62_py.egg-info/entry_points.txt +2 -0
- base62_py-1.3.13/src/base62_py.egg-info/requires.txt +1 -0
- base62_py-1.3.13/src/base62_py.egg-info/top_level.txt +1 -0
- base62_py-1.3.13/tests/test_base62.py +26 -0
base62_py-1.3.13/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Cyril Dever
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: base62-py
|
|
3
|
+
Version: 1.3.13
|
|
4
|
+
Summary: Custom Base-62 Encoder in Python
|
|
5
|
+
Author-email: Cyril Dever <cdever@pep-s.com>
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2024 Cyril Dever
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
|
|
28
|
+
Project-URL: Homepage, https://github.com/cyrildever/base62
|
|
29
|
+
Keywords: base62,base-62,encoder,decoder
|
|
30
|
+
Classifier: Programming Language :: Python :: 3
|
|
31
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
32
|
+
Classifier: Operating System :: OS Independent
|
|
33
|
+
Requires-Python: >=3.10.2
|
|
34
|
+
Description-Content-Type: text/markdown
|
|
35
|
+
License-File: LICENSE
|
|
36
|
+
Requires-Dist: py-utls>=0.3.0
|
|
37
|
+
|
|
38
|
+
# base62-ts
|
|
39
|
+
_Custom Base-62 Encoder_
|
|
40
|
+
|
|
41
|
+

|
|
42
|
+

|
|
43
|
+

|
|
44
|
+

|
|
45
|
+

|
|
46
|
+
|
|
47
|
+
This repository contains the version of my encoder/decoder for Base-62 in three languages:
|
|
48
|
+
* [Golang](https://github.com/cyrildever/base62);
|
|
49
|
+
* Python;
|
|
50
|
+
* [TypeScript](https://github.com/cyrildever/base62/ts).
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
### Motivation
|
|
54
|
+
|
|
55
|
+
I needed an efficient way to apply a Base-62 encoding/decoding algorithm working the same way in TypeScript/Javascript, Golang and Python environments.
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
### Usage
|
|
59
|
+
|
|
60
|
+
Both versions use the same following dictionary:
|
|
61
|
+
|
|
62
|
+
| Value | Character | Value | Character | Value | Character | Value | Character | Value | Character |
|
|
63
|
+
|:-----:|:---------:|:-----:|:---------:|:-----:|:---------:|:-----:|:---------:|:-----:|:---------:|
|
|
64
|
+
| 0 | `0` | 13 | `d` | 26 | `q` | 39 | `D` | 52 | `Q` |
|
|
65
|
+
| 1 | `1` | 14 | `e` | 27 | `r` | 40 | `E` | 53 | `R` |
|
|
66
|
+
| 2 | `2` | 15 | `f` | 28 | `s` | 41 | `F` | 54 | `S` |
|
|
67
|
+
| 3 | `3` | 16 | `g` | 29 | `t` | 42 | `G` | 55 | `T` |
|
|
68
|
+
| 4 | `4` | 17 | `h` | 30 | `u` | 43 | `H` | 56 | `U` |
|
|
69
|
+
| 5 | `5` | 18 | `i` | 31 | `v` | 44 | `I` | 57 | `V` |
|
|
70
|
+
| 6 | `6` | 19 | `j` | 32 | `w` | 45 | `J` | 58 | `W` |
|
|
71
|
+
| 7 | `7` | 20 | `k` | 33 | `x` | 46 | `K` | 59 | `X` |
|
|
72
|
+
| 8 | `8` | 21 | `l` | 34 | `y` | 47 | `L` | 60 | `Y` |
|
|
73
|
+
| 9 | `9` | 22 | `m` | 35 | `z` | 48 | `M` | 61 | `Z` |
|
|
74
|
+
| 10 | `a` | 23 | `n` | 36 | `A` | 49 | `N` | | |
|
|
75
|
+
| 11 | `b` | 24 | `o` | 37 | `B` | 50 | `O` | | |
|
|
76
|
+
| 12 | `c` | 25 | `p` | 38 | `C` | 51 | `P` | | |
|
|
77
|
+
|
|
78
|
+
In other words, they use the following base: `0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ`.
|
|
79
|
+
|
|
80
|
+
```console
|
|
81
|
+
pip install base62-py
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
```python
|
|
85
|
+
from base62 import decode, encode
|
|
86
|
+
|
|
87
|
+
value = 18969
|
|
88
|
+
|
|
89
|
+
encoded = encode(value)
|
|
90
|
+
|
|
91
|
+
# 4VX
|
|
92
|
+
print(encoded)
|
|
93
|
+
|
|
94
|
+
decoded = decode(encoded)
|
|
95
|
+
|
|
96
|
+
assert value == decoded
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
### Tests
|
|
101
|
+
|
|
102
|
+
```console
|
|
103
|
+
$ pip install -e . && python3 -m unittest discover
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
### License
|
|
108
|
+
|
|
109
|
+
Both versions are available under a MIT license (see [LICENSE](LICENSE)).
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
<hr />
|
|
113
|
+
© 2021-2024 Cyril Dever. All rights reserved.
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# base62-ts
|
|
2
|
+
_Custom Base-62 Encoder_
|
|
3
|
+
|
|
4
|
+

|
|
5
|
+

|
|
6
|
+

|
|
7
|
+

|
|
8
|
+

|
|
9
|
+
|
|
10
|
+
This repository contains the version of my encoder/decoder for Base-62 in three languages:
|
|
11
|
+
* [Golang](https://github.com/cyrildever/base62);
|
|
12
|
+
* Python;
|
|
13
|
+
* [TypeScript](https://github.com/cyrildever/base62/ts).
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### Motivation
|
|
17
|
+
|
|
18
|
+
I needed an efficient way to apply a Base-62 encoding/decoding algorithm working the same way in TypeScript/Javascript, Golang and Python environments.
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
### Usage
|
|
22
|
+
|
|
23
|
+
Both versions use the same following dictionary:
|
|
24
|
+
|
|
25
|
+
| Value | Character | Value | Character | Value | Character | Value | Character | Value | Character |
|
|
26
|
+
|:-----:|:---------:|:-----:|:---------:|:-----:|:---------:|:-----:|:---------:|:-----:|:---------:|
|
|
27
|
+
| 0 | `0` | 13 | `d` | 26 | `q` | 39 | `D` | 52 | `Q` |
|
|
28
|
+
| 1 | `1` | 14 | `e` | 27 | `r` | 40 | `E` | 53 | `R` |
|
|
29
|
+
| 2 | `2` | 15 | `f` | 28 | `s` | 41 | `F` | 54 | `S` |
|
|
30
|
+
| 3 | `3` | 16 | `g` | 29 | `t` | 42 | `G` | 55 | `T` |
|
|
31
|
+
| 4 | `4` | 17 | `h` | 30 | `u` | 43 | `H` | 56 | `U` |
|
|
32
|
+
| 5 | `5` | 18 | `i` | 31 | `v` | 44 | `I` | 57 | `V` |
|
|
33
|
+
| 6 | `6` | 19 | `j` | 32 | `w` | 45 | `J` | 58 | `W` |
|
|
34
|
+
| 7 | `7` | 20 | `k` | 33 | `x` | 46 | `K` | 59 | `X` |
|
|
35
|
+
| 8 | `8` | 21 | `l` | 34 | `y` | 47 | `L` | 60 | `Y` |
|
|
36
|
+
| 9 | `9` | 22 | `m` | 35 | `z` | 48 | `M` | 61 | `Z` |
|
|
37
|
+
| 10 | `a` | 23 | `n` | 36 | `A` | 49 | `N` | | |
|
|
38
|
+
| 11 | `b` | 24 | `o` | 37 | `B` | 50 | `O` | | |
|
|
39
|
+
| 12 | `c` | 25 | `p` | 38 | `C` | 51 | `P` | | |
|
|
40
|
+
|
|
41
|
+
In other words, they use the following base: `0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ`.
|
|
42
|
+
|
|
43
|
+
```console
|
|
44
|
+
pip install base62-py
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
from base62 import decode, encode
|
|
49
|
+
|
|
50
|
+
value = 18969
|
|
51
|
+
|
|
52
|
+
encoded = encode(value)
|
|
53
|
+
|
|
54
|
+
# 4VX
|
|
55
|
+
print(encoded)
|
|
56
|
+
|
|
57
|
+
decoded = decode(encoded)
|
|
58
|
+
|
|
59
|
+
assert value == decoded
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
### Tests
|
|
64
|
+
|
|
65
|
+
```console
|
|
66
|
+
$ pip install -e . && python3 -m unittest discover
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
### License
|
|
71
|
+
|
|
72
|
+
Both versions are available under a MIT license (see [LICENSE](LICENSE)).
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
<hr />
|
|
76
|
+
© 2021-2024 Cyril Dever. All rights reserved.
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# pyproject.toml
|
|
2
|
+
|
|
3
|
+
[build-system]
|
|
4
|
+
requires = ["setuptools>=58.1.0", "wheel"]
|
|
5
|
+
build-backend = "setuptools.build_meta"
|
|
6
|
+
|
|
7
|
+
[project]
|
|
8
|
+
name = "base62-py"
|
|
9
|
+
version = "1.3.13"
|
|
10
|
+
description = "Custom Base-62 Encoder in Python"
|
|
11
|
+
readme = "README.md"
|
|
12
|
+
authors = [{ name = "Cyril Dever", email = "cdever@pep-s.com" }]
|
|
13
|
+
license = { file = "LICENSE" }
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Programming Language :: Python :: 3",
|
|
16
|
+
"License :: OSI Approved :: MIT License",
|
|
17
|
+
"Operating System :: OS Independent",
|
|
18
|
+
]
|
|
19
|
+
keywords = [
|
|
20
|
+
"base62",
|
|
21
|
+
"base-62",
|
|
22
|
+
"encoder",
|
|
23
|
+
"decoder"
|
|
24
|
+
]
|
|
25
|
+
dependencies = [
|
|
26
|
+
"py-utls>=0.3.0"
|
|
27
|
+
]
|
|
28
|
+
requires-python = ">=3.10.2"
|
|
29
|
+
|
|
30
|
+
[project.urls]
|
|
31
|
+
Homepage = "https://github.com/cyrildever/base62"
|
|
32
|
+
|
|
33
|
+
[project.scripts]
|
|
34
|
+
base62-py = "base62.__main__:main"
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def main(args):
|
|
5
|
+
"""
|
|
6
|
+
Encode/Decode an integer back-and-forth its Base-62 string representation
|
|
7
|
+
|
|
8
|
+
Arguments
|
|
9
|
+
---------
|
|
10
|
+
value: string
|
|
11
|
+
the value to encode or decode
|
|
12
|
+
-o --operation: string
|
|
13
|
+
the operation to process: decode|encode
|
|
14
|
+
|
|
15
|
+
Usage
|
|
16
|
+
-----
|
|
17
|
+
$ python -m base62 -o decode 4VX
|
|
18
|
+
"""
|
|
19
|
+
print(args)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
if __name__ == "__main__":
|
|
23
|
+
parser = argparse.ArgumentParser()
|
|
24
|
+
parser.add_argument("value", help="the value to encode or decode", required=True)
|
|
25
|
+
parser.add_argument(
|
|
26
|
+
"-o",
|
|
27
|
+
"--operation",
|
|
28
|
+
help="the operation to process: decode|encode",
|
|
29
|
+
required=True,
|
|
30
|
+
)
|
|
31
|
+
args = parser.parse_args()
|
|
32
|
+
|
|
33
|
+
main(args)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
CHARSET = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import math
|
|
2
|
+
|
|
3
|
+
from base62 import CHARSET
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def decode(value: str) -> int:
|
|
7
|
+
"""
|
|
8
|
+
Takes an encoded base-62 string and returns its integer value
|
|
9
|
+
|
|
10
|
+
:param value: The Base-62 encoded string
|
|
11
|
+
:type value: str
|
|
12
|
+
:return: The decoded number
|
|
13
|
+
:rtype: int
|
|
14
|
+
"""
|
|
15
|
+
decoded = 0
|
|
16
|
+
for i in range(len(value)):
|
|
17
|
+
idx = len(value) - i - 1
|
|
18
|
+
n = CHARSET.index(value[idx])
|
|
19
|
+
if n == -1:
|
|
20
|
+
raise Exception("not a base-62 input")
|
|
21
|
+
decoded += int(n * math.pow(62, i))
|
|
22
|
+
return decoded
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
from pyutls import euclidean_division
|
|
2
|
+
|
|
3
|
+
from base62 import CHARSET
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def encode(value: int) -> str:
|
|
7
|
+
"""
|
|
8
|
+
Returns the Base62-encoded string representation of the passed number
|
|
9
|
+
|
|
10
|
+
:param value: The integer to encode
|
|
11
|
+
:type value: int
|
|
12
|
+
:return: The base-62 representation
|
|
13
|
+
:rtype: str
|
|
14
|
+
"""
|
|
15
|
+
if value == 0:
|
|
16
|
+
return "0"
|
|
17
|
+
encoded = ""
|
|
18
|
+
while value > 0:
|
|
19
|
+
value, idx = euclidean_division(value, 62)
|
|
20
|
+
encoded = CHARSET[idx] + encoded
|
|
21
|
+
return encoded
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: base62-py
|
|
3
|
+
Version: 1.3.13
|
|
4
|
+
Summary: Custom Base-62 Encoder in Python
|
|
5
|
+
Author-email: Cyril Dever <cdever@pep-s.com>
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2024 Cyril Dever
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
|
|
28
|
+
Project-URL: Homepage, https://github.com/cyrildever/base62
|
|
29
|
+
Keywords: base62,base-62,encoder,decoder
|
|
30
|
+
Classifier: Programming Language :: Python :: 3
|
|
31
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
32
|
+
Classifier: Operating System :: OS Independent
|
|
33
|
+
Requires-Python: >=3.10.2
|
|
34
|
+
Description-Content-Type: text/markdown
|
|
35
|
+
License-File: LICENSE
|
|
36
|
+
Requires-Dist: py-utls>=0.3.0
|
|
37
|
+
|
|
38
|
+
# base62-ts
|
|
39
|
+
_Custom Base-62 Encoder_
|
|
40
|
+
|
|
41
|
+

|
|
42
|
+

|
|
43
|
+

|
|
44
|
+

|
|
45
|
+

|
|
46
|
+
|
|
47
|
+
This repository contains the version of my encoder/decoder for Base-62 in three languages:
|
|
48
|
+
* [Golang](https://github.com/cyrildever/base62);
|
|
49
|
+
* Python;
|
|
50
|
+
* [TypeScript](https://github.com/cyrildever/base62/ts).
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
### Motivation
|
|
54
|
+
|
|
55
|
+
I needed an efficient way to apply a Base-62 encoding/decoding algorithm working the same way in TypeScript/Javascript, Golang and Python environments.
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
### Usage
|
|
59
|
+
|
|
60
|
+
Both versions use the same following dictionary:
|
|
61
|
+
|
|
62
|
+
| Value | Character | Value | Character | Value | Character | Value | Character | Value | Character |
|
|
63
|
+
|:-----:|:---------:|:-----:|:---------:|:-----:|:---------:|:-----:|:---------:|:-----:|:---------:|
|
|
64
|
+
| 0 | `0` | 13 | `d` | 26 | `q` | 39 | `D` | 52 | `Q` |
|
|
65
|
+
| 1 | `1` | 14 | `e` | 27 | `r` | 40 | `E` | 53 | `R` |
|
|
66
|
+
| 2 | `2` | 15 | `f` | 28 | `s` | 41 | `F` | 54 | `S` |
|
|
67
|
+
| 3 | `3` | 16 | `g` | 29 | `t` | 42 | `G` | 55 | `T` |
|
|
68
|
+
| 4 | `4` | 17 | `h` | 30 | `u` | 43 | `H` | 56 | `U` |
|
|
69
|
+
| 5 | `5` | 18 | `i` | 31 | `v` | 44 | `I` | 57 | `V` |
|
|
70
|
+
| 6 | `6` | 19 | `j` | 32 | `w` | 45 | `J` | 58 | `W` |
|
|
71
|
+
| 7 | `7` | 20 | `k` | 33 | `x` | 46 | `K` | 59 | `X` |
|
|
72
|
+
| 8 | `8` | 21 | `l` | 34 | `y` | 47 | `L` | 60 | `Y` |
|
|
73
|
+
| 9 | `9` | 22 | `m` | 35 | `z` | 48 | `M` | 61 | `Z` |
|
|
74
|
+
| 10 | `a` | 23 | `n` | 36 | `A` | 49 | `N` | | |
|
|
75
|
+
| 11 | `b` | 24 | `o` | 37 | `B` | 50 | `O` | | |
|
|
76
|
+
| 12 | `c` | 25 | `p` | 38 | `C` | 51 | `P` | | |
|
|
77
|
+
|
|
78
|
+
In other words, they use the following base: `0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ`.
|
|
79
|
+
|
|
80
|
+
```console
|
|
81
|
+
pip install base62-py
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
```python
|
|
85
|
+
from base62 import decode, encode
|
|
86
|
+
|
|
87
|
+
value = 18969
|
|
88
|
+
|
|
89
|
+
encoded = encode(value)
|
|
90
|
+
|
|
91
|
+
# 4VX
|
|
92
|
+
print(encoded)
|
|
93
|
+
|
|
94
|
+
decoded = decode(encoded)
|
|
95
|
+
|
|
96
|
+
assert value == decoded
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
### Tests
|
|
101
|
+
|
|
102
|
+
```console
|
|
103
|
+
$ pip install -e . && python3 -m unittest discover
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
### License
|
|
108
|
+
|
|
109
|
+
Both versions are available under a MIT license (see [LICENSE](LICENSE)).
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
<hr />
|
|
113
|
+
© 2021-2024 Cyril Dever. All rights reserved.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
MANIFEST.in
|
|
3
|
+
README.md
|
|
4
|
+
pyproject.toml
|
|
5
|
+
src/base62/__init__.py
|
|
6
|
+
src/base62/__main__.py
|
|
7
|
+
src/base62/base62.py
|
|
8
|
+
src/base62/decoder.py
|
|
9
|
+
src/base62/encoder.py
|
|
10
|
+
src/base62_py.egg-info/PKG-INFO
|
|
11
|
+
src/base62_py.egg-info/SOURCES.txt
|
|
12
|
+
src/base62_py.egg-info/dependency_links.txt
|
|
13
|
+
src/base62_py.egg-info/entry_points.txt
|
|
14
|
+
src/base62_py.egg-info/requires.txt
|
|
15
|
+
src/base62_py.egg-info/top_level.txt
|
|
16
|
+
tests/test_base62.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
py-utls>=0.3.0
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
base62
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
from unittest import TestCase
|
|
2
|
+
|
|
3
|
+
from base62 import decode, encode
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class TestEncoder(TestCase):
|
|
7
|
+
def test_decode(self):
|
|
8
|
+
ref = 18969
|
|
9
|
+
value = "4VX"
|
|
10
|
+
found = decode(value)
|
|
11
|
+
self.assertEqual(found, ref)
|
|
12
|
+
|
|
13
|
+
with self.assertRaises(Exception):
|
|
14
|
+
decode("not-a-base-62%")
|
|
15
|
+
|
|
16
|
+
found = decode("0")
|
|
17
|
+
self.assertEqual(found, 0)
|
|
18
|
+
|
|
19
|
+
def test_encode(self):
|
|
20
|
+
value = 18969
|
|
21
|
+
expected = "4VX"
|
|
22
|
+
found = encode(value)
|
|
23
|
+
self.assertEqual(found, expected)
|
|
24
|
+
|
|
25
|
+
found = encode(0)
|
|
26
|
+
self.assertEqual(found, "0")
|