Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何猜测已知字符串哈希中缺少的字符?_Python_Python 3.x_Hash_Md5_Brute Force - Fatal编程技术网

Python 如何猜测已知字符串哈希中缺少的字符?

Python 如何猜测已知字符串哈希中缺少的字符?,python,python-3.x,hash,md5,brute-force,Python,Python 3.x,Hash,Md5,Brute Force,我不擅长编程。事实上,我已经理解了这个算法,但它在实现编码时并不起作用。所以我在这里解释 我有一个词:“狮子座” 和md5 hash=“55db5fa990642A061cdfcf73b5027b” 如果我只知道md5散列和“li?nf?re”这个词,我怎么能猜出真正的单词呢? 这是我最后一次尝试python import hashlib import sys import string characters = string.printable for x, y in character

我不擅长编程。事实上,我已经理解了这个算法,但它在实现编码时并不起作用。所以我在这里解释

我有一个词:“狮子座” 和md5 hash=“55db5fa990642A061cdfcf73b5027b”

如果我只知道md5散列和“li?nf?re”这个词,我怎么能猜出真正的单词呢? 这是我最后一次尝试python

import hashlib
import sys
import string

characters = string.printable

for x, y  in characters:
    content= 'li'+ x + 'nf' + y + 're'
    if hashlib.md5(content).hexdigest() == "55dbbb5fa990642a061cdfcf73b5027b":
        print content
        sys.exit(0)

搜索模式必须允许两个可能的字母“o”和“i”。。。因此,您需要考虑一对字母(python调用这些元组)

使用了模式2字母模式:“li%snf%sre”。
%s
替换第一(f)个和第二(s)个案例


在您的示例中,两个字符的x相同。。。暴力施法(唯一的方法)需要2个字符的组合(或双循环),这是否回答了您的问题@梅尔文:谢谢你的建议,但我不认为这是一样的
import hashlib
import sys
import string


def findWord(md5Key, pattern):
    charList = [(f,s) for f in string.printable for s in string.printable]

    for f,s  in charList:
        content= pattern % (f,s)
        if hashlib.md5(content.encode()).hexdigest() == md5Key:
            print('found',content)
            return content
    return None

findWord("55dbbb5fa990642a061cdfcf73b5027b", 'li%snf%sre')