所有可能的 8 个符号字符串的生成器。暴力破解8符号密码。 Python
我需要编写生成器来生成所有可能的 8 个符号字符串。 从这样的符号数组:
leters = ['1','2','3','4','5','6','7','8','9','0','q','w','e','r','t','y','u','i','o','p','a','s','d','f','g','h','j','k','l','z','x','c','v','b','n','m']
骨架看起来像这样:
def generator():
"""
here algorithm
"""
yield string
假设返回这样的列表 ['00000001','00000002','00000003', ......'mmmmmmmm']
I need to write generator which yield all possible 8 symbols strings.
From array of symbols like this:
leters = ['1','2','3','4','5','6','7','8','9','0','q','w','e','r','t','y','u','i','o','p','a','s','d','f','g','h','j','k','l','z','x','c','v','b','n','m']
The skeleton looks like this:
def generator():
"""
here algorithm
"""
yield string
suppose to return list like this ['00000001','00000002','00000003', ......'mmmmmmmm']
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
itertools.combinations()
和itertools.combinations_with_replacement()
返回一个生成器,我在示例中使用
print()
来说明输出。将其替换为yield
,以获得生成器。如果您对包含英文字母和数字的所有 8 个字母密码进行暴力破解,则需要迭代约 2.8 万亿个字符串
编辑
如果您以某种方式知道没有重复元素,请使用
permutations
这会为您提供 ab 和 ba
对于最常见的暴力序列,请使用
itertools.product()
如 Cosmologicon 的解决方案中所示itertools.combinations()
anditertools.combinations_with_replacement()
return a generatorI am using
print()
in the examples to illustrate the output. Substitute it withyield
, to get a generator.If you brute force it for all 8 letter passwords containing english letters and digits, you're looking to iterate over ~ 2.8 trillion strings
EDIT
If you somehow know there are no repeated elements, use
permutations
this gives you both ab and ba
For the most general brute force sequence use
itertools.product()
as in Cosmologicon's solution编辑:让它给你字符串而不是元组:
EDIT: to have it give you strings rather than tuples:
顺便说一句,字母有两个 T。
By the way, letters has two T's.
我也想知道如何做到这一点,这就是我想出的办法,我尝试了几种方法,但是当我这样写时,它比其他方法快得多......如果我没有看到,请lmk
I was wondering how to do this as well and this is what I came up with I tried it a couple ways but when I wrote it like this it went way quicker than the others...please lmk if I am not seeing