前言:
这题跟python有关,可见看懂python代码还是很有必要得,需要有一些python基础才好
easychallenge:
题目: 下载后来发现是一个.pyc为后缀得文件,查找资料可知,该文件为python编译后得文件,所以我们第一步应该是反编译,将其转成py文件
我们使用python得uncompyle6库来进行反编译,安装出错或者太慢试试这个,
pip install -i https://pypi.doubanio.com/simple/ 包名
下面给出如何使用得命令
uncompyle6 -o F:\桌面\ F:\桌面\tmp\1.pyc
然后将反编译后得py文件内容给出:
1 # uncompyle6 version 3.7.3 2 # Python bytecode 2.7 (62211) 3 # Decompiled from: Python 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:43:08) [MSC v.1926 32 bit (Intel)] 4 # Embedded file name: ans.py 5 # Compiled at: 2018-08-09 11:29:44 6 import base64 7 8 def encode1(ans): 9 s = '' 10 for i in ans: 11 x = ord(i) ^ 36 12 x = x + 25 13 s += chr(x) 14 15 return s 16 17 18 def encode2(ans): 19 s = '' 20 for i in ans: 21 x = ord(i) + 36 22 x = x ^ 36 23 s += chr(x) 24 25 return s 26 27 28 def encode3(ans): 29 return base64.b32encode(ans) 30 31 32 flag = ' ' 33 print 'Please Input your flag:' 34 flag = raw_input() 35 final = 'UC7KOWVXWVNKNIC2XCXKHKK2W5NLBKNOUOSK3LNNVWW3E===' 36 if encode3(encode2(encode1(flag))) == final: 37 print 'correct' 38 else: 39 print 'wrong'
可以看到通过该py文件加密后得final是 UC7KOWVXWVNKNIC2XCXKHKK2W5NLBKNOUOSK3LNNVWW3E=== ,然后我们修改一下encode3 encode2 encode1,将其改成decode1 decode2 decode3,
下面给出代码:
1 # uncompyle6 version 3.7.3 2 # Python bytecode 2.7 (62211) 3 # Decompiled from: Python 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:43:08) [MSC v.1926 32 bit (Intel)] 4 # Embedded file name: ans.py 5 # Compiled at: 2018-08-09 11:29:44 6 import base64 7 8 def decode3(ans): 9 s = '' 10 for i in ans: 11 # x = ord(i) ^ 36 12 # x = x + 25 13 14 x = ord(i) -25 15 x = x ^ 36 16 s += chr(x) 17 18 return s 19 20 21 def decode2(ans): 22 s = '' 23 for i in ans: 24 # x = ord(i) + 36 25 # x = x ^ 36 26 27 x = i ^ 36 28 x = x - 36 29 s += chr(x) 30 31 return s 32 33 34 def decode1(ans): 35 return base64.b32decode(ans) 36 37 38 final = b'UC7KOWVXWVNKNIC2XCXKHKK2W5NLBKNOUOSK3LNNVWW3E===' 39 print(decode3(decode2(decode1(final))))
反向即可解码