base系列解码程序
由于在ctf比赛中经常会遇到base系列的编码,不好判断是哪种类型,于是自己编写了一个解码程序(少了base36和base128),不需要去网上找了(而且有些还收费)
#coding:utf-8
import base64,base36,base58,base91,base92,base62
import binascii
import re
def base_decode(n):
m=''
flag=False
try:
if re.search('[a-e]',n):
m=base64.b16decode(n,True)
else:
m=base64.b16decode(n)
except binascii.Error:
pass
else:
flag=True
print("base16deocde:",m)
return flag
#'''''''''''''''''''''''''''''''''
try:
m=base64.b32decode(n)
except binascii.Error:
pass
else:
flag=True
print("base32deocde:",m)
return flag
#'''''''''''''''''''''''''''''''''
try:
m=base58.b58decode(n)
except ValueError:
pass
else:
m=str(m)[2:-1]
if '\\x' in m:
pass
else:
flag=True
print("base58deocde:",m)
mm=str(base91.decode(n))
if '\\x' not in mm:
print("maybe base91decode:",mm)
return flag
#'''''''''''''''''''''''''''''''''
try:
m=base62.decodebytes(n)
except ValueError:
pass
else:
m=str(m)
if '\\x' in m:
pass
else:
flag=True
print("base62deocde:",m)
return flag
#'''''''''''''''''''''''''''''''''
try:
m=base64.b64decode(n)
except binascii.Error:
pass
else:
m=str(m)
if '\\x' in m:
pass
else:
flag=True
print("base64deocde:",m)
return flag
#'''''''''''''''''''''''''''''''''
try:
m=base64.b85decode(n)
except ValueError:
pass
else:
m=str(m)
if '\\x' in m:
pass
else:
print("base_b85deocde:",m)
flag=True
return flag
#'''''''''''''''''''''''''''''''''
try:
m=base64.a85decode(n)
except ValueError:
pass
else:
m=str(m)
if '\\x' in m:
pass
else:
print("base_a85deocde:",m)
flag=True
return flag
#'''''''''''''''''''''''''''''''''
try:
m=base91.decode(n)
except ValueError:
pass
else:
m=str(m)
if '\\x' in m:
pass
else:
print("base91deocde:",m)
flag=True
return flag
#'''''''''''''''''''''''''''''''''
try:
m=base92.decode(n)
except ValueError:
pass
else:
flag=True
print("base92deocde:",m)
return flag
return flag
#'''''''''''''''''''''''''''''''''
if __name__=='__main__':
print("******There are no base36 and base128******")
while(1):
x=input("input the string(q to quit):")
if x=='q':
break
a=base_decode(x)
if a==True:
print('\n')
else:
print("Fail")
在代码中所涉及到的base编码系列应该都能解码。
有发现错误请大家提出。
安装
pip install base58
pip install base91
pip install base92
pip install pybase62
关于base92模块在python3中会出错的问题
python官网提供的pypi是基于python2的,在python3里运行会报错,下面提供了修改方法。
具体改法:
- 将base92文件夹里的__init__.py中的base92改为.base92
-
修改base92文件夹里的base92.py
- 111行:basestring改为str
- 122、135和163行:/改为//,如
- 111行:basestring改为str
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。