1 #-*-coding:utf-8-*-
2 #author:hell0_w
3 #本人博客:http://hell0w.cnblogs.com/
4
5 import base64
6 import bubblepy
7 import urllib
8 import quopri
9 import cgi
10 import HTMLParser
11
12 #加密函数:
13 def base16_encode(content):
14 return base64.b16encode(content)
15 def base32_encode(content):
16 return base64.b32encode(content)
17 def base64_encode(content):
18 return base64.b64encode(content)
19 def BubbleBabble_encode(content):
20 return bubblepy.BubbleBabble().encode(content)
21 def url_encode(content):
22 return urllib.quote(content)
23 def dec_binary(content):
24 list = []
25 for i in content.split(' '):
26 list.append(bin(int(i)).replace('0b',''))
27 return list
28 def str_binary(content):
29 list = []
30 for i in content:
31 list.append(ord(i))
32 list1 = []
33 for j in list:
34 list1.append(bin(int(j)).replace('0b',''))
35 return list1
36 def quoted_printable_encode(content):
37 return quopri.encodestring(content)
38 def HtmlParser_encode(content):
39 return cgi.escape(content)
40
41
42 #解密函数:
43 def base16_decode(content):
44 return base64.b16decode(content)
45 def base32_decode(content):
46 return base64.b32decode(content)
47 def base64_decode(content):
48 return base64.b64decode(content)
49 def BubbleBabble_decode(content):
50 return bubblepy.BubbleBabble().decode(content)
51 def url_decode(content):
52 return urllib.unquote(content)
53 def binary_dec(content):
54 list = []
55 for i in content.split(' '):
56 list.append(int(i,2))
57 return list
58 def binary_str(content):
59 list = []
60 for i in content.split(' '):
61 list.append(int(i,2))
62 list1 =[]
63 for j in list:
64 list1.append(chr(j))
65 return ''.join(list1)
66 def quoted_printable_decode(content):
67 return quopri.decodestring(content)
68 def HtmlParser_decode(content):
69 return HTMLParser.HTMLParser().unescape(content)
70
71
72 def encode():
73 print "[1]:base16编码"
74 print "[2]:base32编码"
75 print "[3]:base64编码"
76 print "[4]:BubbleBabble编码"
77 print "[5]:url编码"
78 print "[6]:十进制转二进制"
79 print "[7]:字符串转二进制"
80 print "[8]:quoted-printable编码"
81 print "[9]:HTML实体编码"
82 operation = input("请选择:")
83 strs = raw_input("请输入需要加密的字符串:")
84 if operation == 1:
85 try:
86 print "[+]加密的结果为:%s " % base16_encode(strs)
87 except Exception,e:
88 print e
89
90 elif operation == 2:
91 try:
92 print "[+]加密的结果为:%s " % base32_encode(strs)
93 except Exception,e:
94 print e
95
96 elif operation == 3:
97 try:
98 print "[+]加密的结果为:%s " % base64_encode(strs)
99 except Exception,e:
100 print e
101
102 elif operation == 4:
103 try:
104 print "[+]加密的结果为:%s " % BubbleBabble_encode(strs)
105 except Exception,e:
106 print e
107
108 elif operation == 5:
109 try:
110 print "[+]加密的结果为:%s " % url_encode(strs)
111 except Exception,e:
112 print e
113
114 elif operation == 6:
115 try:
116 print "[+]加密的结果为:%s " % dec_binary(strs)
117 except Exception,e:
118 print e
119
120 elif operation == 7:
121 try:
122 print "[+]加密的结果为:%s " % str_binary(strs)
123 except Exception,e:
124 print e
125
126 elif oper