base家族

base64

换表的情况

无法直接使用base64.b64decode(enc)来直接解出,但是可以将密文排序为原表的密文再解

例子:

1
2
3
4
5
6
7
8
9
10
11
12
13
import base64

enc = 'AMHo7dLxUEabf6Z3PdWr6cOy75i4fdfeUzL17kaV7rG='

model = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" #正常表

str = 'qaCpwYM2tO/RP0XeSZv8kLd6nfA7UHJ1No4gF5zr3VsBQbl9juhEGymc+WTxIiDK' #被改变了的base64的表
#这段是排序归位
dnc = ''
for i in range(len(enc)):
dnc += model[str.find(enc[i])]

print(base64.b64decode(dnc).decode())

或者通过建立映射字典的方式来还原(感谢青丝独奏):

1
2
3
4
5
6
7
8
9
10
11
import base64

newtable = bytes(i for i in range(32, 32+64))
# print(newtable)
table = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
bbb = str.maketrans(dict(zip(newtable, table)))
# print(bbb)
flag = bytes(flag).decode()
fff = flag.translate(bbb)
# print(fff)
res = base64.b64decode(fff)

base58

md,整了不少,装不上,那就毛一个脚本:

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
def b58encode(tmp: str) -> str:
tmp = list(map(ord, tmp))
temp = tmp[0]
base58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
for i in range(len(tmp) - 1):
temp = temp * 256 + tmp[i + 1]
tmp = []
while True:
tmp.insert(0, temp % 58)
temp = temp // 58
if temp == 0:
break
temp = ""
for i in tmp:
temp += base58[i]
return temp


def b58decode(tmp: str) -> str:
import binascii
base58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
temp = []
for i in tmp:
temp.append(base58.index(i))
tmp = temp[0]
for i in range(len(temp) - 1):
tmp = tmp * 58 + temp[i + 1]
return binascii.unhexlify(hex(tmp)[2:].encode("utf-8")).decode("UTF-8")