简体   繁体   English

Python - 如何从特定长度的给定字符生成wordlist

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

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 max length )? 如何从特定长度(或从最小长度到最大长度的字长)的给定字符生成单词列表? I have tried itertools.combinations_with_replacements and itertools.permutations , but it does not help. 我已经尝试过itertools.combinations_with_replacementsitertools.permutations ,但它没有帮助。 They does not have all the word lists that it should return. 他们没有应该返回的所有单词列表。 Any help will be greatly appreciated. 任何帮助将不胜感激。 Thank you. 谢谢。

Use itertools.product : 使用itertools.product

>>> import itertools
>>>
>>> chrs = 'abc'
>>> n = 2
>>>
>>> for xs in itertools.product(chrs, repeat=n):
...     print ''.join(xs)
...
aa
ab
ac
ba
bb
bc
ca
cb
cc

To get word from min length to max length: 从最小长度到最大长度获取单词:

chrs = 'abc'
min_length, max_length = 2, 5    
for n in range(min_length, max_length+1):
    for xs in itertools.product(chrs, repeat=n):
        print ''.join(xs)
from itertools import product

def allwords(chars, length):
    for letters in product(chars, repeat=length):
        yield ''.join(letters)

def main():
    letters = "abc"
    for wordlen in range(3, 5):
        for word in allwords(letters, wordlen):
            print(word)

if __name__=="__main__":
    main()

returns 回报

aaa
aab
aac
aba
abb

...

ccbc
ccca
cccb
cccc    

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: 我还没有足够的声誉来评论,因此,要根据上面的itertools示例制作完整列表:

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. 这样,您就可以在列表中拥有从长度1到n的所有单词。

def word_gen(start= 3,end= 3, elements = 1): """ Hud Seidu Daannaa Wordlist gen MSC InfoSec, CEH" def word_gen(start = 3,end = 3,elements = 1):“”“Hud Seidu Daannaa Wordlist gen MSC InfoSec,CEH”

README
#for start&end
#e.g. start= 3,end= 3
#means first words to last words should be 3 characters

#for elements
1 is asci
2 is numbers
3 is asci&numbers
"""
import itertools
#types of elements
if elements ==1: elements= 'abcdefghijklmnopqrstuvwxyx'
if elements ==2: elements= '0123456789'
if elements== 3: elements= 'abcdefghijklmnopqrstuvwxyx0123456789'
else: pass
wl = []
for i in range(start,end+1):
    for xs in itertools.product(elements, repeat=i):
        wl.append(''.join(xs))
return wl

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 生成已知字符的单词表 - Generate wordlist with known characters Python-从给定字符创建单词列表,该字符列表仅包含4-5个字母和5-6个数字 - Python - create wordlist from given characters of that contain 4-5 letters and 5-6 numbers ONLY 如何从python Regex中的给定字符串中提取特定长度的字符 - How to extract characters of particular length from a given string in python Regex 如何从python中的给定字符生成英语单词 - How can i generate the english words from given characters in python 如何生成Python中给定长度的所有配置 - How to generate all configurations of a given length in Python 从出现的给定字符中生成固定长度的随机字符串,发生次数相等 - Generate random strings of fixed length from given characters with equal occurance 如何根据给定的字符和长度生成排列列表? - How do I generate a list of permutations based on given characters and a length? 从随机字符串中找到单词列表中的单词(Python) - Find words in wordlist from random string of characters (Python) 从python Regex中的给定字符串中提取特定长度的字符 - Extraction of characters of particular length from a given string in python Regex 简单的代码即可生成特定类型的单词表 - Simple code to generate a wordlist of specific type
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM