python - Make python code for searching through dictionary more efficent (vigenere cipher)
问题描述
I'm writing some code to go through the vigenere cipher with different possibilities, and then making it only add the list to the possible options that result in a word when decrypted (that way I don't get thousands of print outs, I only get told with the most likely possibilities).
Here's the code so far
def vigenere(input):
print("VIGENERE")
key = ""
keyList = []
textList = []
for word in englishDictionary:
key = re.sub('[\W_]+', '', word)
if key[:len(input)] not in keyList:
while len(key) < len(input):
key = key + key
keyLetters = list(key.upper())
keyNumbers = []
for x in keyLetters:
keyNumbers.append(alphaNum.get(x))
vigenereOutput = ""
for z in list(input):
try:
keyNum = int(keyNumbers[0])
except IndexError:
pass
keyNum = keyNum - 1
inbetween = int(alphaNum.get(z)) - keyNum
del keyNumbers[0]
if inbetween < 1:
inbetween = 26 + inbetween
vigenereOutput = vigenereOutput + numAlpha.get(str(inbetween))
if vigenereOutput in englishDictionary:
keyList.append(key[:len(input)])
textList.append(vigenereOutput)
if len(keyList) > 0:
for keyEntry in len(keyList):
print("Key:", keyList[keyEntry])
print("Text:", textList[keyEntry])
print()
The englishDictionary is a list of all the words in my dictionary text file (fairly big file, but using a small one would ruin the point of this decoder)
Right now however it takes over 20 minutes to go through the entire dictionary... how can I speed this process up?
解决方案
推荐阅读
- image - Twilio 向 WhatsApp 发送多张图片
- parallel-processing - 使用多线程进行滚动功能
- go - 使用 golang 在 gcp 中创建实例时添加启动脚本
- javascript - 为什么脚本不运行?
- c# - SSRS 报告服务 Rest API 未经授权
- microsoft-graph-api - 通过 Graph API 将成员添加到组的权限
- xml - XSLT 将相邻值分组为均匀分布
- javascript - Chart.js 图表未显示在 React 引导模式中
- typescript - Typescript 和 Redux:绑定元素“字符串”隐式具有“任何”类型
- kubernetes - Kubernetes 在所有 php-fpm pod 上执行命令