密钥已知DES解密英文正常中文乱码

查看 59|回复 5
作者:天空宫阙   
DES解密英文正常中文乱码,求正确的解密方式
大概率的加密方式:DES/CBC/PKCS5Padding
密钥:iscooler
加密数据比较长放蓝奏云了,https://wwyh.lanzouw.com/ixfwr2e4lhdc
[Python] 纯文本查看 复制代码from Crypto.Cipher import DES # pip install pycryptodome
from base64 import b64encode,b64decode, encodebytes
from Crypto.Util.Padding import unpad
with open('encrypted_data.txt','r',encoding='utf-8') as f:
    encrypted_data = f.read()
'''
大概率的加密方式:DES/CBC/PKCS5Padding
密钥:iscooler
'''
encrypted_data = b64decode(encrypted_data)
# padded_data = unpad(encrypted_data, 8)  # 移除PKCS5填充
cryptor = DES.new('iscooler'.encode(), DES.MODE_CBC)
ciphertext = cryptor.decrypt(encrypted_data)
print(ciphertext)
result =  ciphertext.decode('UTF-8').strip()
print(result)
尝试过decode('UTF-8'), unpad(encrypted_data, 8) 未成功

密钥, 英文

天空宫阙
OP
  

提供的正确解密的代码不限于python,nodejs,java都可以
grekevin   

[Python] 纯文本查看 复制代码from Crypto.Cipher import DES
from base64 import b64decode
from Crypto.Util.Padding import unpad
with open('encrypted_data.txt', 'r', encoding='utf-8') as f:
    encrypted_data = f.read()
# 大概率的加密方式:DES/CBC/PKCS5Padding
# 密钥:iscooler
key = 'iscooler'.encode()
iv = b'12345678'  # 需要一个8字节的IV
encrypted_data = b64decode(encrypted_data)
cryptor = DES.new(key, DES.MODE_CBC, iv)
ciphertext = cryptor.decrypt(encrypted_data)
padded_data = unpad(ciphertext, DES.block_size)  # 移除PKCS5填充
result = padded_data.decode('UTF-8').strip()
print(result)
天空宫阙
OP
  


grekevin 发表于 2024-11-3 16:52
[mw_shl_code=python,true]from Crypto.Cipher import DES
from base64 import b64decode
from Crypto.Ut ...

中文确实正常了,但是前面几位还是乱码,整段不好直接用json解析。能否完美解密?
[color=]Ka +V%ticle"
:0,"meta":{},"format":"rf","version":"1.0","segments":[{"sentid":"31910541474925569","section_begin":null,"segid":"0","start":"690","en":"A powerful ocean storm caused deadly floods and
landslides in the northern part of Vietnam over the weekend.","end":10479,"cn":"一场强烈的海洋风暴
在周末给越南北部地区带来了致命的洪水和山体滑坡。"
天空宫阙
OP
  


grekevin 发表于 2024-11-3 16:52
[mw_shl_code=python,true]from Crypto.Cipher import DES
from base64 import b64decode
from Crypto.Ut ...

前面几位正确的是 {"read_article":0,"meta":{},"format":"rf","version":"1.0","segments":[{"sentid"
grekevin   


天空宫阙 发表于 2024-11-3 17:09
前面几位正确的是 {"read_article":0,"meta":{},"format":"rf","version":"1.0","segments":[{"sentid"

加密和解密的Iv要一样
您需要登录后才可以回帖 登录 | 立即注册

返回顶部