逆向python-trade

.py与.pyc文件比较

https://www.cnblogs.com/zyy98877/p/8650119.html

.pyc文件反编译

https://www.cnblogs.com/pppig/p/11423274.html

一个数异或一个数再次异或这个数,便是它本身。

a^b=c    c^b=a

10^11=01   01^11=10

在控制台输入

uncompyle6 文件名.pyc

反编译得到文件内容:

# uncompyle6 version 3.6.4
# Python bytecode 2.7 (62211)
# Decompiled from: Python 3.8.1 (tags/v3.8.1:1b293b6, Dec 18 2019, 23:11:46) [MSC v.1916 64 bit (AMD64)]
# Embedded file name: 1.py
# Compiled at: 2017-06-03 10:20:43
import base64

def encode(message):
    s = ''
    for i in message:
        x = ord(i) ^ 32
        x = x + 16
        s += chr(x)

    return base64.b64encode(s)


correct = 'XlNkVmtUI1MgXWBZXCFeKY+AaXNt'
flag = ''
print 'Input flag:'
flag = raw_input()
if encode(flag) == correct:
    print 'correct'
else:
    print 'wrong'
View Code

文件是由python2编译的。将其调整为python3标准格式。

import base64


def encode(message):
    s = ''
    for i in message:
        x = ord(i) ^ 32 # 异或 这里x为char ord 8进制,这里会默认转化为int类型
        x = x + 16      # x + 16
        s += chr(x)     # int 转 char
    # python2 使用ASCII字符集 latin-1 作为字符编码标准
    # python3 使用unicode字符集 utf-8 作为字符编码标准
    # 这里可能说法不正确,有明白的,望告知。
    # 将字符串s用lantin-1编码
    return base64.b64encode(s.encode("latin-1"))


correct = 'XlNkVmtUI1MgXWBZXCFeKY+AaXNt'

flag = ''
print("Input flag")
flag = input()
# 以lantin-1解码
if encode(flag).decode("latin-1") == correct:
    print("correct")
else:
    print("wrong")
View Code

解密:

import base64


s = base64.b64decode("XlNkVmtUI1MgXWBZXCFeKY+AaXNt") # 得到一个byte流
f = "" # flag
for i in s:
    x = i - 16  # i(byte值) - 16 默认转为 int
    x = chr(x)  # x 转为 char
    x = ord(x) ^ 32 # 异或 32
    f += chr(x) # 转 char
print(f)
View Code

猜你喜欢

转载自www.cnblogs.com/TNTBomb/p/12606622.html