0

我正在寻找执行字典攻击并想知道如何创建一个单词列表,其中每个单词包含 5 个字母 (af) 和 5 个数字仅 (2-9) 或 6 个字母 (af) 和 4 个数字 (2-9)(我不能这样做)。

这是我到目前为止(从这里):

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)

谢谢

4

3 回答 3

0

只需编写一个函数,返回字符串中有效字母和数字的数量并测试返回值。

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-11T20:38:08.053 回答
0

您可以单独检查每个排列,如果满足条件,则将其添加到数组中。只需编写一个简单的布尔函数来计算每个函数中的数字和字母,并检查条件。

于 2015-10-11T20:40:23.433 回答
0

这将从总数 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']
于 2015-10-11T20:45:15.747 回答