Skip to content

Instantly share code, notes, and snippets.

@dp7k
Created September 12, 2015 13:26
Show Gist options
  • Select an option

  • Save dp7k/a03c6a3d8db35a032184 to your computer and use it in GitHub Desktop.

Select an option

Save dp7k/a03c6a3d8db35a032184 to your computer and use it in GitHub Desktop.
wordlist/dictionary generator for brute-force attacks
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
import hashlib
import itertools
import string
# generator
def brute_force_generator(chars, max_length):
for length in range(1, max_length+1):
product = itertools.product(chars, repeat=length)
for t in product:
yield ''.join(t)
generator = brute_force_generator(string.ascii_lowercase, 5)
""" # test
l = list(generator)
assert len(l) == 26**1 + 26**2 + 26**3 + 26**4 + 26**5
assert '' not in l
assert 'x' in l
assert 'foo' in l
assert 'foobar' not in l
print('OK.')
exit()
"""
# example
md5_hash = '21232f297a57a5a743894a0e4a801fc3'
for key in generator:
if hashlib.md5(key.encode('utf-8')).hexdigest() == md5_hash:
print('Key found: %s' % (key))
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment