首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >加密挑战4个问题

加密挑战4个问题
EN

Stack Overflow用户
提问于 2018-08-27 06:51:20
回答 1查看 226关注 0票数 0

对于Cryptopals Challenge4 set 1,我没有得到预期的结果。

该程序的概念是检查这些300ish字符串中是否有任何字符串被单个字符XORd。因此,我的解决方案是使用暴力,获取每个字符串,将其与键盘上的每个字符进行XOR运算,然后检查这些结果中是否有生成英语句子的结果。如果不是,则检查下一个字符串。下面是我的代码:

代码语言:javascript
复制
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看到的解决方案。我只是不确定为什么我的程序不能识别明文不在字典中。

(我知道使用评分系统对每个字符串进行评分,看看它是否更接近英语会更容易,但这是我目前选择的方法,直到我弄清楚如何让评分函数工作/:)

EN

回答 1

Stack Overflow用户

发布于 2019-04-10 20:20:55

你的字典"possible_plaintexts“在印刷的时候是什么样子的?你能从打印的文本中找出解决方案吗?它是如何打印的?

解密的字符串还应包含'\n‘字符。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52030824

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档