Python - 如何从特定长度的给定字符生成wordlist

Aam*_*amu 4 python python-2.7 dictionary-attack

我想进行字典攻击,为此我需要单词列表.如何从特定长度(或从最小长度到最大长度的字长)的给定字符生成单词列表?我曾尝试itertools.combinations_with_replacementsitertools.permutations,但它并不能帮助.他们没有应该返回的所有单词列表.任何帮助将不胜感激.谢谢.

fal*_*tru 5

用途itertools.product:

>>> import itertools
>>>
>>> chrs = 'abc'
>>> n = 2
>>>
>>> for xs in itertools.product(chrs, repeat=n):
...     print ''.join(xs)
...
aa
ab
ac
ba
bb
bc
ca
cb
cc
Run Code Online (Sandbox Code Playgroud)

从最小长度到最大长度获取单词:

chrs = 'abc'
min_length, max_length = 2, 5    
for n in range(min_length, max_length+1):
    for xs in itertools.product(chrs, repeat=n):
        print ''.join(xs)
Run Code Online (Sandbox Code Playgroud)