1. 程式人生 > >常見編碼解碼腳本

常見編碼解碼腳本

table 我們 edi except 函數 運行 div clas href

在平時我們會遇到各種各樣的編碼,在這裏,我總結了一些常見的編碼,並不是很全

嘗試著做了個編碼解碼的匯總,並且寫了個腳本出來,由於python功底不是很強,所以可能會有不到之處,還望各位多多指正

附上腳本:

  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 operation == 8: 127 try: 128 print "[+]加密的結果為:%s " % quoted_printable_encode(strs) 129 except Exception,e: 130 print e 131 132 elif operation == 9: 133 try: 134 print "[+]加密的結果為:%s " % HtmlParser_encode(strs) 135 except Exception,e: 136 print e 137 else: 138 print "error!" 139 encode() 140 141 142 def decode(): 143 print "[1]:base16解碼" 144 print "[2]:base32解碼" 145 print "[3]:base64解碼" 146 print "[4]:BubbleBabble解碼" 147 print "[5]:url解碼" 148 print "[6]:二進制轉十進制" 149 print "[7]:二進制轉字符串" 150 print "[8]:quoted-printable解碼" 151 print "[9]:HTML實體解碼" 152 operation = input("請選擇:") 153 strs = raw_input("請輸入需要解密的字符串:") 154 if operation == 1: 155 try: 156 print "[+]解密的結果為:%s " % base16_decode(strs) 157 except Exception,e: 158 print "Error!Not base16 encoding!" 159 160 elif operation == 2: 161 try: 162 print "[+]解密的結果為:%s " % base32_decode(strs) 163 except Exception,e: 164 print "Error!Not base32 encoding!" 165 166 elif operation == 3: 167 try: 168 print "[+]解密的結果為:%s " % base64_decode(strs) 169 except Exception,e: 170 print "Error!Not base64 encoding!" 171 172 elif operation == 4: 173 try: 174 print "[+]解密的結果為:%s " % BubbleBabble_decode(strs) 175 except Exception,e: 176 print "Error!Not BubbleBabble encoding!" 177 178 elif operation == 5: 179 try: 180 print "[+]解密的結果為:%s " % url_decode(strs) 181 except Exception,e: 182 print "Error!Not url encoding!" 183 184 elif operation == 6: 185 try: 186 print "[+]解密的結果為:%s " % binary_dec(strs) 187 except Exception,e: 188 print "Error!Not binary encoding!" 189 190 elif operation == 7: 191 try: 192 print "[+]解密的結果為:%s " % binary_str(strs) 193 except Exception,e: 194 print "Error!Not binary encoding!" 195 196 elif operation == 8: 197 try: 198 print "[+]解密的結果為:%s " % quoted_printable_decode(strs) 199 except Exception,e: 200 print "Error!Not quoted-printable encoding!" 201 202 elif operation == 9: 203 try: 204 print "[+]解密的結果為:%s " % HtmlParser_decode(strs) 205 except Exception,e: 206 print "Error!Not HtmlParser encoding!" 207 else: 208 print "error!" 209 decode() 210 211 212 def main(): 213 print "[1]:加密" 214 print "[2]:解密" 215 operation = input("請選擇:") 216 if operation == 1: 217 encode() 218 elif operation == 2: 219 decode() 220 else: 221 print "error!" 222 main() 223 224 if __name__ == __main__: 225 main()

運行示例:

加密:

技術分享

解密:

技術分享

本文固定連接:http://www.cnblogs.com/hell0w/p/7512211.html 轉載請註明出處,謝謝!

常見編碼解碼腳本