-
Notifications
You must be signed in to change notification settings - Fork 1
/
decrypt.py
52 lines (39 loc) · 1.05 KB
/
decrypt.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
# ==============================================================================
#
# Use:
# decrypt(b'SGVsbG8gV29ybGQh')
# => b'Hello World!'
#
# ==============================================================================
def char_array():
char = []
for i in range(26):
char.append(chr(65+i)) # All uppercase letters
for i in range(26):
char.append(chr(97+i)) # All lowercase letters
for i in range(10):
char.append(chr(48+i)) # All 10 digits
char.append('+')
char.append('/')
return char
def decrypt(s):
char = char_array()
if type(s) is not bytes:
s = str(s).encode('utf-8')
p = 0
while s[-1:] == b'=':
p += 2
s = s[:-1]
b = ''
for c in s:
t = char.index(chr(c))
t = bin(t)[2:]
t = (6 - len(t)) * '0' + t
b += t
b = b[:len(b)-p]
o = ''
while len(b) > 0:
t = b[:8]
o += chr(int(t, 2))
b = b[8:]
return o.encode('utf-8')