X书x-mini-sig_x-mini-mua
一切皆可逆:
麻烦博主给个demo的app链接
DES对称加密及三重DES(3DES)
Codeooo:
[code=python]
import base64
import binascii
from Crypto.Cipher import DES
from Crypto.Util.Padding import unpad,pad
ciphertext = "1MpdxK203+ZrnyxuJRrYatKSBxHUIi1TSdQF2BQKXOG54plwfaB2GA=="
key = "11" # 密钥长度不足8字节
# 补全密钥至8字节长度
key = key.ljust(8, "\x00").encode("utf-8")
print(key)
decoded_ciphertext = base64.b64decode(ciphertext)
cipher = DES.new(key, DES.MODE_ECB)
decrypted = cipher.decrypt(decoded_ciphertext)
plaintext = unpad(decrypted, 8)
plaintext = plaintext.decode("utf-8")
print(plaintext)
enc_string = '1MpdxK203+ZrnyxuJRrYatKSBxHUIi1TSdQF2BQKXOG54plwfaB2GA=='
key = '11'.encode('utf-8')
key = key + b'\0' * (8 - len(key) % 8) ## add padding
a = DES.new(key, DES.MODE_ECB,) # This gives me error
decrypted = a.decrypt(base64.b64decode(enc_string))
print(unpad(decrypted,8).decode())
[/code]
|