Logo 逆向知识库

易语言

易语言#

分析一般需要:

 

“加密数据”的坑——DES算法魔改#

易语言的 DES 和常规的不同,详见 易语言支持库内的DES算法分析 - 吾爱破解 - 52pojie.cn

魔改后的 DES 算法如下

from Crypto.Cipher import DES
import struct

def reverse_bytes(b):
    assert type(b) == bytes
    ba = bytearray(b)
    for i in range(0, len(b)):
        ba[i] = int(format(b[i], '0>8b')[::-1], 2)
    return bytes(ba)

def get_new_key(key):
    ba = bytearray(8)
    i = 0
    for b in key:
        ba[i] = b ^ ba[i]
        i = i + 1 if i < 8 else 0
    return bytes(ba)

# zero padding
def padding(d):
    ba = bytearray(d)
    while len(ba) % 8 != 0:
        ba.append(0)

    return bytes(ba)

def append_len(d):
    assert type(d) == bytes
    length = struct.pack('<L', len(d))

    return bytes(length + d)

def remove_len(d):
    assert type(d) == bytes
    return d[4:]

def e_des_encrypt(plain, key):
    des = DES.new(reverse_bytes(get_new_key(key)), DES.MODE_ECB)
    return des.encrypt(padding(append_len(plain)))

def e_des_decrypt(raw, key):
    des = DES.new(reverse_bytes(get_new_key(key)), DES.MODE_ECB)
    t = des.decrypt(raw)
    return remove_len(t)

if __name__ == "__main__":
    plain = b'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
    key = b'4g3n71u0'
    ciph = e_des_encrypt(plain, key)
    print(ciph.hex().upper())
    print(e_des_decrypt(ciph, key).decode())
Last updated on