Cryptopals挑战4关注

问题描述 投票:0回答:1

我没有得到Cryptopals challenge 4 set 1的预期结果。

程序的概念,以检查这些300个字符串中的任何一个是否被单个字符XORd。因此,使用蛮力,我的解决方案是取每个字符串,将其与键盘上的每个字符进行异或,并检查这些结果是否产生英语句子。如果没有,那么检查下一个字符串。这是我的代码:

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函数是有效的,因为它在最后一个问题上正常工作,我对字符串进行了每个可能的字符串XOR。而且我也知道明文是我提供的那个,我看到了解决方案。我只是不确定为什么我的程序没有认识到明文不在字典中。

(我知道使用评分系统对每个字符串进行评分,以确定它是否更接近英语会更容易,但这是我现在选择这样做的方式,直到我弄清楚如何让我的评分函数起作用/: )

python-3.x cryptography
1个回答
0
投票

当你打印时,你的词典“possible_plaintexts”怎么样?你能在印刷文本中发现解决方案吗?怎么印?

解密的字符串也应该有一个'\ n'字符。

© www.soinside.com 2019 - 2024. All rights reserved.