misc-python脚本学习笔记
base64
用base64模块导入
所以写:import base64
这个是base64编码
ZmxhZ3s5YTQ4ZGRhZDI2NTYzODVmY2U1OGFmNDdhMGVmNTZjZn0=
赋值给b,所以写
b = "ZmxhZ3s5YTQ4ZGRhZDI2NTYzODVmY2U1OGFmNDdhMGVmNTZjZn0="
再导入函数解码
base64模块可以有以下函数
b = base64.b64decode(b)
再打印
print(b)
完整代码:
import base64 #导入base64模块
b = "ZmxhZ3s5YTQ4ZGRhZDI2NTYzODVmY2U1OGFmNDdhMGVmNTZjZn0=" #将编码赋值给b
b = base64.b64decode(b) #导入函数解码
print(b) #打印
base32
和上面一样
函数要改成base64.b32decode
import base64 #导入base64模块
b = "MZWGCZ33HFQTIODEMRQWIMRWGU3DGOBVMZRWKNJYMFTDIN3BGBSWMNJWMNTH2===" #将编码赋值给b
b = base64.b32decode(b) #导入函数解码
print(b) #打印
base16
一样,改函数
base64.b16decode(b)
import base64 #导入base64模块
b = "666C61677B39613438646461643236353633383566636535386166343761306566353663667D" #将编码赋值给b
b = base64.b16decode(b) #导入函数解码
print(b) #打印
16进制
其实16进制就是base16字母改小写
导入binascii模块
import binascii #导入模块
b = "666c61677b39613438646461643236353633383566636535386166343761306566353663667d" #将编码赋值给b
b = binascii.unhexlify(b) #导入函数解码
print(b) #打印
url解码
从urllib.parse包中导入unquote模块
from urllib.parse import unquote
from urllib.parse import unquote
b = "flag%7B9a48ddad2656385fce58af47a0ef56cf%7D"
b = unquote(b)
print(b)
base64换表
a = "5Mc58bPHLiAx7J8ocJIlaVUxaJvMcoYMaoPMaOfg15c475tscHfM/8=="
#将密文赋值给a
b = 'qvEJAfHmUYjBac+u8Ph5n9Od17FrICL/X0gVtM4Qk6T2z3wNSsyoebilxWKGZpRD'
#要换得表
c = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
#标准表
print (base64.b64decode(a.translate(str.maketrans(b,c))))
'''
str.maketrans(b, c),将 b 中的字符替换到c 中对应的字符
translate() 方法使用前面创建的转换表来替换 a 中的字符
'''
import base64
a = "5Mc58bPHLiAx7J8ocJIlaVUxaJvMcoYMaoPMaOfg15c475tscHfM/8==" #将密文赋值给a
b = 'qvEJAfHmUYjBac+u8Ph5n9Od17FrICL/X0gVtM4Qk6T2z3wNSsyoebilxWKGZpRD' #要换得表
c = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" #标准表
print (base64.b64decode(a.translate(str.maketrans(b,c))))
'''
str.maketrans(b, c),将 b 中的字符替换到c 中对应的字符
translate() 方法使用前面创建的转换表来替换 a 中的字符
'''
二进制转16进制
b = hex(int(b, 2))[2:]
二进制字符串b转换为一个十六进制字符串
import binascii
b = "01001011010010010101100101010101010101010101010100110010010100110100100101010110010101110100011101000011010101010011001101001101010010110101101001001000010001100100100101010110010000110100101101001001010101100100101101000110010010110100111001001011010011000100101101011010010000110101011101001001010101000101001101001110010001110100001001001010010001010101100101010110010000110101011101001111010000100100110001010110010001010100110101000010010100010101000001000110010010100100010101001011010011110100101101010000010010110100011001010111010001110100100101010011010000110101011001001011010100100100101001000101010010110101010100110010010101100100011101010110010100010101011001001101010101100100110001000101010010100101101001000111010101110101100101010101010100110100110101001011010100100101011001011000010000010101011001001011010100110100011101000110010000110101100001010101010101010101001101000110010011100101001001001110010001100100111100110011010000110101011101001010010110100100101001000110010010010101001101010011010001100100101101010110010010110101010001001011010100110011001001010111010001110100001001010011010001100100011101010110010100110100011001001011010010100100010101000110010010010101011001010100010100010100101101011010010010100100010001000001010011010100010001011010010010110100100101011001010001100100110101010100001100100101001101001001010101100100101001000101010100010101011001001011010101110100111101000010010000110101011001000111010101100101010001001101010010100100111001001100010001110101011101011010010000110101001101001010010101100101011001010110010001010101001001000011010101010100111001001110010010100100010101010001010101010101001001010010010010100100101001001010010101100100010101010010010011000100110101001010010110100100110001010111010110010101011001010011010011110100101101001110010010110100010101010101010100100100101101010011010010110101010100110010010101010100011101010110001100110100110001001101010100100100110001000101001100100011001000110010010100110100101001000010010010110100011001001101010100110101001101011000010010110100100101011001010001010100101100110110010010110101001101001001010110100100100001000101001101000101010001001010010100010100101101010101001101100101000100111101001111010011110100111101"
b = hex(int(b, 2))[2:]
print(b)
二进制转ascii
c = binascii.unhexlify(b)
16解码
import binascii
b = "01001011010010010101100101010101010101010101010100110010010100110100100101010110010101110100011101000011010101010011001101001101010010110101101001001000010001100100100101010110010000110100101101001001010101100100101101000110010010110100111001001011010011000100101101011010010000110101011101001001010101000101001101001110010001110100001001001010010001010101100101010110010000110101011101001111010000100100110001010110010001010100110101000010010100010101000001000110010010100100010101001011010011110100101101010000010010110100011001010111010001110100100101010011010000110101011001001011010100100100101001000101010010110101010100110010010101100100011101010110010100010101011001001101010101100100110001000101010010100101101001000111010101110101100101010101010100110100110101001011010100100101011001011000010000010101011001001011010100110100011101000110010000110101100001010101010101010101001101000110010011100101001001001110010001100100111100110011010000110101011101001010010110100100101001000110010010010101001101010011010001100100101101010110010010110101010001001011010100110011001001010111010001110100001001010011010001100100011101010110010100110100011001001011010010100100010101000110010010010101011001010100010100010100101101011010010010100100010001000001010011010100010001011010010010110100100101011001010001100100110101010100001100100101001101001001010101100100101001000101010100010101011001001011010101110100111101000010010000110101011001000111010101100101010001001101010010100100111001001100010001110101011101011010010000110101001101001010010101100101011001010110010001010101001001000011010101010100111001001110010010100100010101010001010101010101001001010010010010100100101001001010010101100100010101010010010011000100110101001010010110100100110001010111010110010101011001010011010011110100101101001110010010110100010101010101010100100100101101010011010010110101010100110010010101010100011101010110001100110100110001001101010100100100110001000101001100100011001000110010010100110100101001000010010010110100011001001101010100110101001101011000010010110100100101011001010001010100101100110110010010110101001101001001010110100100100001000101001101000101010001001010010100010100101101010101001101100101000100111101001111010011110100111101"
b = hex(int(b, 2))[2:]
c = binascii.a2b_hex(b)
print(c)