This commit is contained in:
Andrej730
2024-11-27 11:07:30 +05:00
parent 25eecded4e
commit ab069f431a
5 changed files with 19 additions and 14 deletions
+4 -4
View File
@@ -33,7 +33,7 @@ from functools import reduce
chars = string.digits + string.ascii_uppercase + string.ascii_lowercase + "_$"
def compress(g):
def compress(g: str) -> str:
bs = [int(g[i : i + 2], 16) for i in range(0, len(g), 2)]
def b64(v, l=4):
@@ -42,7 +42,7 @@ def compress(g):
return "".join([b64(bs[0], 2)] + [b64((bs[i] << 16) + (bs[i + 1] << 8) + bs[i + 2]) for i in range(1, 16, 3)])
def expand(g):
def expand(g: str) -> str:
def b64(v):
return reduce(lambda a, b: a * 64 + b, map(lambda c: chars.index(c), v))
@@ -53,9 +53,9 @@ def expand(g):
return "".join(["%02x" % b for b in bs])
def split(g):
def split(g: str) -> str:
return "{%s-%s-%s-%s-%s}" % (g[:8], g[8:12], g[12:16], g[16:20], g[20:])
def new():
def new() -> str:
return compress(uuid.uuid4().hex)