抱歉,您的浏览器无法访问本站
本页面需要浏览器支持(启用)JavaScript
了解详情 >


Python BinaryConversion

Binary.py
#coding:utf-8
import re
import argparse

def bintostr(text):
text = text.replace(' ','')
text = re.findall(r'.{8}',text)
s = map(lambda x:chr(int(x,2)),text) #批量二进制转十进制
flag = ''.join(s)
return (flag)

def asciitostr(text):
if ' ' in text:
text = text.split(' ')
elif ',' in text:
text = text.split(',')
s = map(lambda x:chr(int(x)),text)
flag = ''.join(s)
return flag

def hextostr(text):
text = re.findall(r'.{2}',text)
#print text
s = map(lambda x:chr(int(x,16)),text)
#print s
flag = ''.join(s)
return flag


if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument("-b")
parser.add_argument("-a")
parser.add_argument("-x")
argv = parser.parse_args()
#print argv
if argv.b:
res = bintostr(argv.b)
print (res)
elif argv.a:
res = asciitostr(argv.a)
print (res)
elif argv.x:
res = hextostr(argv.x)
print (res)

推荐阅读
Python ASCII 字符串 转换 Python ASCII 字符串 转换 Cryptography Cryptography Python Baconian Python Baconian Python RailFenceCipher Python RailFenceCipher Python Base Python Base Python Morse Python Morse

留言区

Are You A Robot?