python-3.x - Cryptopals 挑战 4 个问题
问题描述
我没有得到 Cryptopals 挑战 4 第 1 组的预期结果。
程序的概念是检查这 300 个字符串中的任何一个是否已被单个字符异或。所以用蛮力,我的解决方案是获取每个字符串,将它与键盘上的每个字符进行异或,然后检查这些结果中的任何一个是否会产生一个英文句子。如果不是,则检查下一个字符串。这是我的代码:
MY_DICT = {}
index = 0
my_plaintext = "Now that the party is jumping"
#fills the dictionary with hex strings from the txt file
with open("hexstrings.txt") as f:
my_list = f.readlines()
for x in my_list:
MY_DICT[index] = x.rstrip('\n')
index = index + 1
i=0
input() #this is just here to help me keep track of where i am when running it
#this loop fills possible_plaintext with all the possible 255 XORs of the i'th string
#of the dictionary that was previously filler from the txt file
for i in range(326):
possible_plaintexts = brute_force_singlechar_xor(MY_DICT[i])
print(possible_plaintexts)
if possible_plaintexts == my_plaintext: #line of concern
print("ya found it yay :) ")
我确定 myBruteForce 函数可以正常工作,因为它在最后一个问题上正常工作,即我对字符串对每个可能的字符进行异或运算。而且我也知道明文是在我看到解决方案之前提供的。我只是不确定为什么我的程序没有识别出明文不在字典中。
(我知道使用评分系统对每个字符串进行评分,看看它是否接近英语会更容易,但这是我现在选择这样做的方式,直到我弄清楚如何让我的评分功能工作/: )
解决方案
打印时,您的字典“possible_plaintexts”怎么样?你能在印刷文本中找到解决方案吗?它是如何印刷的?
解密后的字符串也应该有一个 '\n' 字符。
推荐阅读
- java - Spring Security SAML 扩展的配置错误:“无法实例化 [org.springframework.security.saml.SAMLBootstrap]”
- elasticsearch - 如何将弹性搜索从 1.7.x 升级到 7.0?
- objective-c - 如何在不同 NSObject 中定义的 NSObject 中引用 IBOutlet
- javascript - 如何在 SVG 圆环图中旋转圆圈?
- python-2.7 - 分布式 Tensorflow 错误:检查失败:DeviceNameUtils::ParseFullName(new_base, &parsed_name)
- asp.net-core - 如何正确重定向到asp.netcore中的页面
- sql - 如何将字符串的特定部分解析为sql中的各个列?
- jenkins - 有没有办法将部署锁定为仅在一天中的特定时间进行?
- postgresql - 为 postgres 副本创建只读用户
- wordpress - 将 jpg 上传到 wordpress 网站会被拒绝