aboutsummaryrefslogtreecommitdiff
path: root/src/utils
diff options
context:
space:
mode:
authorGravatar jesopo2019-12-06 14:29:26 +0000
committerGravatar jesopo2019-12-06 14:29:26 +0000
commitb2127145612957a0d7610449a9c7beefe43de398 (patch)
treed2986aa6d4d4d5c4f41e4c0c139da779ff4b0a24 /src/utils
parentadd utils.parse.shortencode() and utils.parse.shortdecode - effectively base62 (diff)
signature
Revert "add utils.parse.shortencode() and utils.parse.shortdecode - effectively base62"
This reverts commit e71f3bbc36eba8abf616d93fde48cba66b3749f1.
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/parse.py46
1 files changed, 1 insertions, 45 deletions
diff --git a/src/utils/parse.py b/src/utils/parse.py
index f6d43bff..ce2ee793 100644
--- a/src/utils/parse.py
+++ b/src/utils/parse.py
@@ -1,4 +1,4 @@
-import decimal, io, random, typing
+import decimal, io, typing
from . import datetime, errors
COMMENT_TYPES = ["#", "//"]
@@ -120,47 +120,3 @@ def timed_args(args, min_args):
return time, args[1:]
return None, args
-SHORTENCODE_CHARS = list(
- "abcdefghijklmnopqrstuvwxyz"
- "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
- "0123456789")
-
-SHORTENCODE_SALT = "bitbot"
-def _shortencode_salt(salt: str):
- chars = SHORTENCODE_CHARS.copy()
- random.Random(salt).shuffle(chars)
- return chars
-
-def _shortencode_tobase(n: int, base: int) -> typing.List[int]:
- r = []
- while n:
- n, remainder = divmod(n, base)
- r.append(remainder)
- return r
-def _shortencode_frombase(ints: typing.List[int], base: int) -> int:
- n = 0
- for i in ints:
- n = (n*base)+i
- return n
-
-def shortencode_b(bytes: bytes, salt: str=SHORTENCODE_SALT):
- chars = _shortencode_salt(salt)
-
- ints = list(bytes)
- n = _shortencode_frombase(ints, 256)
- r = _shortencode_tobase(n, len(chars))
-
- return "".join(chars[i] for i in reversed(r))
-def shortencode(s: str, salt: str=SHORTENCODE_SALT):
- return shortencode_b(s.encode("latin-1"), salt)
-
-def shortdecode_b(s: str, salt: str=SHORTENCODE_SALT):
- chars = _shortencode_salt(salt)
-
- ints = [chars.index(c) for c in s]
- n = _shortencode_frombase(ints, len(chars))
- r = _shortencode_tobase(n, 256)
-
- return bytes(reversed(r))
-def shortdecode(s: str, salt: str=SHORTENCODE_SALT):
- return shortdecode_b(s, salt).decode("latin-1")