我想保存解密代码的进度

2024-03-28 23:00:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个代码(Python3.0),可以运行列出的所有可能的字符组合

from itertools import combinations
import hashlib
import os

test1 = 0
test2 = 0
test3 = 0
test4 = 0
test5 = 0
test6 = 0

file = open("/media/pi/AE/Programming/Python/Cicada 3301/Answers.txt", 'a')
char = "`1234567890-=qwertyuiop[]\asdfghjkl;'zxcbvbnm,./ ~!@#$%^&*()_+QWERTYUIOP{}|ASDFGHJKL:ZXCVBNM<>?"
max_length = len(char)

for length in range(1, max_length + 1):
    for test in map(''.join, combinations(char, length)):
        print(test)
        if test1 == "Found":
            print("36 Found")
        if test2 == "Found":
            print("59 Found")
        if test3 == "Found":
            print("d4 Found")
        if test4 == "Found":
            print("46 Found")
        if test5 == "Found":
            print("45 Found")
        if test6 == "Found":
            print("51236 Found")
        hashedmd5 = hashlib.md5(test.encode('utf-8'))
        hashed512 = hashlib.sha512(test.encode('utf-8'))
        #print("md5 = "+hashedmd5.hexdigest())
        #print("sha512 = "+hashed512.hexdigest())
        if hashedmd5.hexdigest() == "36367763ab73783c7af284446c":
            file.write("36367763ab73783c7af284446c"+hashedmd5.hexdigest()+test+"\n")
            test1 = "Found"
        if hashedmd5.hexdigest() == "59466b4cd653239a311cb7116":
            file.write("59466b4cd653239a311cb7116="+hashedmd5.hexdigest()+"="+test+"\n")
            test2 = "Found"
        if hashedmd5.hexdigest() == "d4618dee09a8425893dc7500b":
            file.write("d4618dee09a8425893dc7500b="+hashedmd5.hexdigest()+"="+test+"\n")
            test3 = "Found"
        if hashedmd5.hexdigest() == "464fdaf1672d7bef5e891c6e227":
            file.write("464fdaf1672d7bef5e891c6e227="+hashedmd5.hexdigest()+"="+test+"\n")
            test4 = "Found"
        if hashedmd5.hexdigest() == "4568926a49fb4f45132c2a8b4":
            file.write("4568926a49fb4f45132c2a8b4="+hashedmd5.hexdigest()+"="+test+"\n")
            test5 = "Found"
        if hashed512.hexdigest() == "36367763ab73783c7af284446c59466b4cd653239a311cb7116d4618dee09a8425893dc7500b464fdaf1672d7bef5e891c6e2274568926a49fb4f45132c2a8b4":
            file.write("36367763ab73783c7af284446c59466b4cd653239a311cb7116d4618dee09a8425893dc7500b464fdaf1672d7bef5e891c6e2274568926a49fb4f45132c2a8b4="+hashed512.hexdigest()+"="+test+"\n")
            test6 = "Found"

我想将其编程为从我选择的组合开始,并从那里继续。我该怎么做呢


1条回答
网友
1楼 · 发布于 2024-03-28 23:00:15

首先,您需要将combinations(更好的是,整个map表达式`)替换为一个自定义生成器,该生成器将接受调用者提供的起点,并从那里开始递增组合。如果您不知道如何编写生成器,那么现在是学习的好时机:为这个(相对)简单的应用程序学习这些教程

然后,您需要简单地升级程序以接受指定的起点,并将其传递到生成器中

这能让你动起来吗

相关问题 更多 >