Skip to content

Instantly share code, notes, and snippets.

@wadefletch
Created March 23, 2015 21:26
Show Gist options
  • Save wadefletch/03261ff27e4bae6bd304 to your computer and use it in GitHub Desktop.
Save wadefletch/03261ff27e4bae6bd304 to your computer and use it in GitHub Desktop.
bruteforce.py
import hashlib
import itertools
import string
import time
import console
def encrypt(data):
return hashlib.md5(data).hexdigest()
def crack(hash, charset, maxlength):
for attempt in (''.join(candidate) for candidate in itertools.chain.from_iterable(itertools.product(charset, repeat=i) for i in range(1, maxlength + 1))):
if encrypt(attempt) == hash:
print 'Found:', attempt
break
if __name__ in '__main__':
password = encrypt('WADE')
s = time.time()
# 62 character charset
alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
crack(password, alphabet, 4)
print 'Finished in', round(s-time.time(), 3)/-1, 'seconds'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment