Skip to content

Commit 221161a

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent d81c5c8 commit 221161a

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

ciphers/base62.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
CHARSET = string.digits + string.ascii_lowercase + string.ascii_uppercase
44

5+
56
def base62_encode(num: int) -> str:
67
"""
78
Encodes a positive integer into a base62 string.
@@ -14,7 +15,7 @@ def base62_encode(num: int) -> str:
1415
"""
1516
if num == 0:
1617
return CHARSET[0]
17-
18+
1819
arr = []
1920
base = len(CHARSET)
2021
while num:
@@ -23,6 +24,7 @@ def base62_encode(num: int) -> str:
2324
arr.reverse()
2425
return "".join(arr)
2526

27+
2628
def base62_decode(string_val: str) -> int:
2729
"""
2830
Decodes a base62 string into a positive integer.
@@ -36,14 +38,16 @@ def base62_decode(string_val: str) -> int:
3638
base = len(CHARSET)
3739
strlen = len(string_val)
3840
num = 0
39-
41+
4042
idx = 0
4143
for char in string_val:
4244
power = strlen - (idx + 1)
4345
num += CHARSET.index(char) * (base**power)
4446
idx += 1
4547
return num
4648

49+
4750
if __name__ == "__main__":
4851
import doctest
52+
4953
doctest.testmod()

0 commit comments

Comments
 (0)