簡體   English   中英

我怎么能猜出已知字符串哈希中缺少的字符?

[英]How can i guess some missing character in known strings hash?

我不擅長編程。 實際上,我已經了解了該算法,但是在將其實現為編碼時卻不起作用。 所以我在這里解釋一下。

我有一個詞 = "lionfire" 和 md5 hash = "55dbbb5fa990642a061cdfcf73b5027b"

如果我只知道 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)

搜索模式必須允許 2 個可能的字母 'o' 和 'i'...所以你需要考慮一對字母(python 調用這些元組)。

使用了模式 2 字母模式:'li%snf%sre'。 %s替代了第一個 (f) 和第二個 (s) 情況。

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')

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM