0%

Python BinaryConversion

Python BinaryConversion

Binary.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
#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)
写文不易,感谢支持!
Writing is not easy. Thank you for your support.