前言:
这次得题目从本质上说没有什么难点,是多次利用base64和16进制编码,层层解开就好,通过这题得代码编写能很好得锻炼python代码能力,一起加油,尝试着自己写写看看把。
混合编码:
题目:JiM3NjsmIzEyMjsmIzY5OyYjMTIwOyYjNzk7JiM4MzsmIzU2OyYjMTIwOyYjNzc7JiM2ODsmIzY5OyYjMTE4OyYjNzc7JiM4NDsmIzY1OyYjNTI7JiM3NjsmIzEyMjsmIzEwNzsmIzUzOyYjNzY7JiMxMjI7JiM2OTsmIzEyMDsmIzc3OyYjODM7JiM1NjsmIzEyMDsmIzc3OyYjNjg7JiMxMDc7JiMxMTg7JiM3NzsmIzg0OyYjNjU7JiMxMjA7JiM3NjsmIzEyMjsmIzY5OyYjMTIwOyYjNzg7JiMxMDU7JiM1NjsmIzEyMDsmIzc3OyYjODQ7JiM2OTsmIzExODsmIzc5OyYjODQ7JiM5OTsmIzExODsmIzc3OyYjODQ7JiM2OTsmIzUwOyYjNzY7JiMxMjI7JiM2OTsmIzEyMDsmIzc4OyYjMTA1OyYjNTY7JiM1MzsmIzc4OyYjMTIxOyYjNTY7JiM1MzsmIzc5OyYjODM7JiM1NjsmIzEyMDsmIzc3OyYjNjg7JiM5OTsmIzExODsmIzc5OyYjODQ7JiM5OTsmIzExODsmIzc3OyYjODQ7JiM2OTsmIzExOTsmIzc2OyYjMTIyOyYjNjk7JiMxMTk7JiM3NzsmIzY3OyYjNTY7JiMxMjA7JiM3NzsmIzY4OyYjNjU7JiMxMTg7JiM3NzsmIzg0OyYjNjU7JiMxMjA7JiM3NjsmIzEyMjsmIzY5OyYjMTE5OyYjNzc7JiMxMDU7JiM1NjsmIzEyMDsmIzc3OyYjNjg7JiM2OTsmIzExODsmIzc3OyYjODQ7JiM2OTsmIzExOTsmIzc2OyYjMTIyOyYjMTA3OyYjNTM7JiM3NjsmIzEyMjsmIzY5OyYjMTE5OyYjNzc7JiM4MzsmIzU2OyYjMTIwOyYjNzc7JiM4NDsmIzEwNzsmIzExODsmIzc3OyYjODQ7JiM2OTsmIzEyMDsmIzc2OyYjMTIyOyYjNjk7JiMxMjA7JiM3ODsmIzY3OyYjNTY7JiMxMjA7JiM3NzsmIzY4OyYjMTAzOyYjMTE4OyYjNzc7JiM4NDsmIzY1OyYjMTE5Ow==
分析: 下载题目后发现,结尾出有等号而且两个,不由的想到Base64,这个编码方式我们前面已经提到过了就不多说了
先写个代码,解解码,python代码如下:
import base64 with open(r'F:\桌面\tmp\1.txt','r') as f: data = f.read() def base64decode(data): data = bytes(data, encoding="utf8") data = base64.b64decode(data) return data print(base64decode(data))
运行结果如下:
1 b'LzExOS8xMDEvMTA4Lzk5LzExMS8xMDkvMTAxLzExNi8xMTEvOTcvMTE2LzExNi85Ny85OS8xMDcvOTcvMTEwLzEwMC8xMDAvMTAxLzEwMi8xMDEvMTEwLzk5LzEwMS8xMTkvMTExLzExNC8xMDgvMTAw'
很明显发现都是$#开头,网上百度一番 https://www.jianshu.com/p/6dcefb2a59b2 ,这篇文章说了 以「&#」开头的后接十进制数字,所以先变成16进制然后解码,思路有了,开始写代码
1 import base64 2 3 with open(r'F:\桌面\tmp\1.txt','r') as f: 4 data = f.read() 5 6 def base64decode(data): 7 data = bytes(data, encoding="utf8") 8 data = base64.b64decode(data) 9 return data 10 11 data= base64decode(data) 12 data = bytes.decode(data) 13 14 15 16 def base16decode(data): 17 m = '' 18 pattern = re.compile('[0-9]{2,3}') 19 result = pattern.findall(data) 20 21 for i in result: 22 m += chr(int(i)) 23 return m 24 25 data = base16decode(data) 26 print(data)
然后我们来看下结果:
1 LzExOS8xMDEvMTA4Lzk5LzExMS8xMDkvMTAxLzExNi8xMTEvOTcvMTE2LzExNi85Ny85OS8xMDcvOTcvMTEwLzEwMC8xMDAvMTAxLzEwMi8xMDEvMTEwLzk5LzEwMS8xMTkvMTExLzExNC8xMDgvMTAw
嗯哼,有点像Base64,先测试下,长度能不能被8整除,如果可以那很大概率是Base64啦,给代码
1 str = 'LzExOS8xMDEvMTA4Lzk5LzExMS8xMDkvMTAxLzExNi8xMTEvOTcvMTE2LzExNi85Ny85OS8xMDcvOTcvMTEwLzEwMC8xMDAvMTAxLzEwMi8xMDEvMTEwLzk5LzEwMS8xMTkvMTExLzExNC8xMDgvMTAw' 2 3 if len(str) % 8 == 0: 4 print(len(str)) 5 print('可以被8整除')
结果是可以被8整除,故我们再用base64解码一下试试,代码后面一起给出,先贴出解码后的结果:
b'/119/101/108/99/111/109/101/116/111/97/116/116/97/99/107/97/110/100/100/101/102/101/110/99/101/119/111/114/108/100'
感觉被套娃了,没办法,再base16解码,给出全部的代码:
1 import base64 2 3 with open(r'F:\桌面\tmp\1.txt','r') as f: 4 data = f.read() 5 6 print(data) 7 def base64decode(data): 8 data = bytes(data, encoding="utf8") 9 data = base64.b64decode(data) 10 return data 11 12 data= base64decode(data) 13 data = bytes.decode(data) 14 print(data) 15 16 17 def base16decode(data): 18 m = '' 19 pattern = re.compile('[0-9]{2,3}') 20 result = pattern.findall(data) 21 22 for i in result: 23 m += chr(int(i)) 24 return m 25 26 data = base16decode(data) 27 print(data) 28 29 data = base64decode(data) 30 print(data) 31 32 def base16decode1(data): 33 m = '' 34 data = bytes.decode(data) 35 pattern = re.compile('[0-9]{3}') 36 result = pattern.findall(data) 37 38 for i in result: 39 m += chr(int(i)) 40 return m 41 print(base16decode1(data))
给出结果:
1 welometottknddefeneworld
哈哈,还是被解出来了,根据解出的步骤反推加密步骤为,先转成16进制,然后再base64编码 ,再转成16 进制,再base64编码,套娃!!!!
除了这种常规思路,我们也可以参考之前那个链接后面提到的方法直接用浏览器解析
参考链接:
https://www.jianshu.com/p/6dcefb2a59b2
https://www.cnblogs.com/yuanchu/p/13467058.html