对于Cryptopals Challenge4 set 1,我没有得到预期的结果。
该程序的概念是检查这些300ish字符串中是否有任何字符串被单个字符XORd。因此,我的解决方案是使用暴力,获取每个字符串,将其与键盘上的每个字符进行XOR运算,然后检查这些结果中是否有生成英语句子的结果。如果不是,则检查下一个字符串。下面是我的代码:
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函数是有效的,因为它正确地解决了最后一个问题,即我对一个字符串执行XORd操作。我也知道明文就是我在bc看到的解决方案。我只是不确定为什么我的程序不能识别明文不在字典中。
(我知道使用评分系统对每个字符串进行评分,看看它是否更接近英语会更容易,但这是我目前选择的方法,直到我弄清楚如何让评分函数工作/:)
发布于 2019-04-10 20:20:55
你的字典"possible_plaintexts“在印刷的时候是什么样子的?你能从打印的文本中找出解决方案吗?它是如何打印的?
解密的字符串还应包含'\n‘字符。
https://stackoverflow.com/questions/52030824
复制相似问题