Python - how to generate wordlist from given characters of specific length

后端 未结 4 734
醉酒成梦
醉酒成梦 2021-01-13 12:30

I want to perform a dictionary attack and for that I need word lists. How to generate word list from given characters of specific length ( or word length from min length to

4条回答
  •  -上瘾入骨i
    2021-01-13 13:03

    This is a naïve implementation:

    list='abcdefg'
    depth=8
    
    def generate(l,d):
      if d<1:
        return
      for c in l:
        if d==1:
          yield c
        else:
          for k in generate(l,d-1):
            yield c+k
    
    for d in range(1,depth):
      for c in generate(list,d):
        print c
    

    I don't have enough reputation to comment yet, so, to make a full list based on the itertools sample above:

    import itertools
    chrs='abc'
    n=6
    for i in range(1,n):
      for xs in itertools.product(chrs, repeat=i):
        print ''.join(xs)
    

    This way, you have all words from length 1 up to n in your list.

提交回复
热议问题