-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtools.py
52 lines (40 loc) · 1.13 KB
/
tools.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import string
def _chr(a):
return f"{string.digits}{string.ascii_lowercase}"[a]
b64map = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
def b64ToHex(a):
d = ""
e = 0
c = 0
for i in range(len(a)):
if list(a)[i] != "=":
v = b64map.index(list(a)[i])
if 0 == e:
e = 1
d += _chr(v >> 2)
c = 3 & v
elif 1 == e:
e = 2
d += _chr(c << 2 | v >> 4)
c = 15 & v
elif 2 == e:
e = 3
d += _chr(c)
d += _chr(v >> 2)
c = 3 & v
else:
e = 0
d += _chr(c << 2 | v >> 4)
d += _chr(15 & v)
if e == 1:
d += _chr(c << 2)
return d
def failed(*args, **kwargs):
print("[\033[31mfailed\033[0m] ", end="")
print(*args, **kwargs)
def success(*args, **kwargs):
print("[\033[32msuccess\033[0m] ", end="")
print(*args, **kwargs)
def info(*args, **kwargs):
print("[\033[34minfo\033[0m] ", end="")
print(*args, **kwargs)