我有一个使用字典解密加密消息的脚本,问题是解密过程产生大量垃圾(a.k.a非ascii)字符。这里是我的代码:排除python中的非ASCII字符
from Crypto.Cipher import AES
import base64
import os
BLOCK_SIZE = 32
PADDING = '{'
# Encrypted text to decrypt
encrypted = "WI4wBGwWWNcxEovAe3p+GrpK1GRRQcwckVXypYlvdHs="
DecodeAES = lambda c, e: c.decrypt(base64.b64decode(e)).rstrip(PADDING)
adib = open('words.txt')
for line in adib.readlines():
secret = line.rstrip('\n')
if (secret[-1:] == "\n"):
print "Error, new line character at the end of the string. This will not match!"
elif (len(secret) >= 32):
print "Error, string too long. Must be less than 32 characters."
else:
# create a cipher object using the secret
cipher = AES.new(secret + (BLOCK_SIZE - len(secret) % BLOCK_SIZE) * PADDING)
# decode the encoded string
decoded = DecodeAES(cipher, encrypted)
print decoded+"\n"
什么,我已经想到了迄今为止被转换decoded
字符串转换为ASCII然后排除非ASCII字符,但没有奏效。
你能准确的一个“words.txt”文件内容例如请 –
它包含了常用词,但这里有一些话 – shoomy
'的 和 一个 一块 集 章 盗 弧 的 编辑 卷 他 插槽名 岛 是 路飞 是 为 与 部分 世界 类别 特别 漫画 维基 维基 百科全书 是 日本 这 动漫 SBS 卷 页 BEGIN END帮助 维基 蓝 船员 从 用户 巴吉 秸秆 肖像 大 他 海盗 新 模板 海军陆战队 他们 不 帽子 魔鬼 FLUSH TOP BOXAD Navibox 猴 他们 鳄鱼 Down 页面 开始 小腿 有 Shichibukai 所有 有 佳能 规则 维基 所有页 水果 佐罗 贝利 海 名 时 图片 一个 乌索普 战 政府 准则 Random' – shoomy