我正在准备一个字典攻击,想知道如何创建一个单词列表,当每个单词包含5个字母( a-f )和5个数字( 2-9 )或6个字母(a-f)和4个数字(2-9) (我不能做什么)时,每个单词都有字母a-f和2-9的每10个字母的排列(我可以这样做)。
以下是我到目前为止(来自here)的信息:
import itertools
chrs = 'abcdef23456789'
n = 2
min_length, max_length = 10, 10
for n in range(min_length, max_length+1):
for xs in itertools.product(chrs, repeat=n):
print ''.join(xs)谢谢
发布于 2015-10-12 04:38:08
只需编写一个函数,返回字符串中有效字母和数字的数量,并测试返回值。
nums = '23456789'
chars = 'abcdef'
def letter_number_count(word):
l,n = 0,0
if len(word) == 10:
for c in word:
if c in nums:
n += 1
elif c in chars:
l += 1
return l,n测试输出
>>> s = 'abcdef2345'
>>> (l,n) = letter_number_count(s)
>>> if (l,n) == (6,4) or (l,n) == (5,5):
... print "Do something"
...
Do something
>>> 发布于 2015-10-12 04:40:23
您可以单独检查每个排列,如果它满足条件,则将其添加到一个数组中。只需编写一个简单的布尔函数,对每个函数中的数字和字母进行计数,并检查条件。
发布于 2015-10-12 04:45:16
这将从总数n中打印出20个这样的排列!其中n= 10 (10!= 3,628,800)
import itertools as it
print(list(map(''.join,it.islice(it.permutations('abcdef23456'), 20))))
['abcdef2345', 'abcdef2346', 'abcdef2354', 'abcdef2356', 'abcdef2364', 'abcdef2365', 'abcdef2435', 'abcdef2436', 'abcdef2453', 'abcdef2456', 'abcdef2463', 'abcdef2465', 'abcdef2534', 'abcdef2536', 'abcdef2543', 'abcdef2546', 'abcdef2563', 'abcdef2564', 'abcdef2634', 'abcdef2635']https://stackoverflow.com/questions/33069660
复制相似问题