我正在尝试构建动态密码恢复工具。您可以指定密码和与未知密码索引对应的未知字符列表。所以,如果你记得90%的密码,并且记不住几个字母,这将为你做一个轻量级的暴力。 我能够将用户提供的密码与未知字符列表相结合;但是,我一直试图打印每个可能的密码。
我被困在这里:
password = 'Dude123'
charList = ['d8','vV','','D8','','','']
finalString = [''.join(set((a, b))) for a, b in zip(password, charList)]
print(finalString) #This statement yields the following
['Dd8', 'uv^', 'd', 'eD8', '1', '2', '3']
现在我需要打印: Dude123 dude123 8ude123 Dvde123 dvde123 8vde123 ...
或者那种效果(它没有以任何特定顺序循环遍历字符,我只需要一个包含所有可能组合的列表。
感谢您的帮助!
戴夫
答案 0 :(得分:3)
你的意思是这样吗?
>>> import itertools
>>>
>>> password = 'Dude123'
>>> charList = ['d8','vV','','D8','','','']
>>>
>>> finalString = [''.join(set((a, b))) for a, b in zip(password, charList)]
>>>
>>> possibles = list(''.join(poss) for poss in itertools.product(*finalString))
>>> possibles
['Dude123', 'DudD123', 'Dud8123', 'Dvde123', 'DvdD123', 'Dvd8123', 'DVde123', 'DVdD123', 'DVd8123', 'dude123', 'dudD123', 'dud8123', 'dvde123', 'dvdD123', 'dvd8123', 'dVde123', 'dVdD123', 'dVd8123', '8ude123', '8udD123', '8ud8123', '8vde123', '8vdD123', '8vd8123', '8Vde123', '8VdD123', '8Vd8123']