【问题标题】:Python - create wordlist from given characters of that contain 4-5 letters and 5-6 numbers ONLYPython - 从仅包含 4-5 个字母和 5-6 个数字的给定字符创建单词表
【发布时间】:2016-01-09 06:07:54
【问题描述】:

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

这是我目前所拥有的(来自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)

谢谢

【问题讨论】:

    标签: python python-3.x itertools dictionary-attack


    【解决方案1】:

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

    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
    >>> 
    

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        【解决方案3】:

        这将从总数 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']
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2022-07-29
          • 1970-01-01
          • 2022-11-16
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多