Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how can implement crunch wordlist generator

This is what I wrote…

def brute(m,pattern=None):
    letters = 'abcdefghijklmnopqrstuvwxyz'
    spec = '#@&$%*()+'
    upper = letters.upper()
    number = '1234567890'
    info = {'@':spec,'^':upper,'%':letters,'*':number}
    chars = [info.get(p,letters) for _,p in zip(range(m),pattern or  letters)]
    def inner(m):
        if m:
            for l in chars[~m]:
                for j in inner(m-1):
                    yield(l+j)
        else:
            for l in chars[~m]:
                yield l
    for i in inner(m-1):
        print(i)
    
 

I want to know how to write a tool similar to crunch in kali…

I would be grateful if you could implement it in Python.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

And why is my code so slow even when I write the output to file??
How to make it faster??

>Solution :

Here is an itertools based approach which might do what you want:

import itertools, string

def brute(m,pattern=None):
    if pattern is None:
        pattern = '%'*m
    letters = string.ascii_lowercase
    upper = string.ascii_uppercase
    spec = '#@&$%*()+'
    number = '1234567890'
    info = {'@':spec,'^':upper,'%':letters,'*':number}
    chars = [info.get(d,letters) for d in pattern]
    return [''.join(p) for p in itertools.product(*chars)]

For example, words = brute(6,'@%%*@^') takes about 2 seconds to evaluate to a list of 14236560 words.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading