#!/usr/bin/env python3 import concurrent.futures import hashlib import os import string import sys # Constants ALPHABET = string.ascii_lowercase + string.digits # Functions def usage(exit_code=0): progname = os.path.basename(sys.argv[0]) print(f'''Usage: {progname} [-a ALPHABET -c CORES -l LENGTH -p PATH -s HASHES] -a ALPHABET Alphabet to use in permutations -c CORES CPU Cores to use -l LENGTH Length of permutations -p PREFIX Prefix for all permutations -s HASHES Path of hashes file''') sys.exit(exit_code) def md5sum(s): ''' Compute md5 digest for given string. ''' # TODO: Use the hashlib library to produce the md5 hex digest of the given # string. return '' def permutations(length, alphabet=ALPHABET): ''' Recursively yield all permutations of alphabet up to given length. ''' # TODO: Use yield to create a generator function that recursively produces # all the permutations of the given alphabet up to the provided length. yield None def flatten(sequence): ''' Flatten sequence of iterators. ''' # TODO: Iterate through sequence and yield from each iterator in sequence. yield None def crack(hashes, length, alphabet=ALPHABET, prefix=''): ''' Return all password permutations of specified length that are in hashes by sequentially trying all permutations. ''' # TODO: Return list comprehension that iterates over a sequence of # candidate permutations and checks if the md5sum of each candidate is in # hashes. return [] def whack(arguments): ''' Call the crack function with the specified list of arguments ''' return [] def smash(hashes, length, alphabet=ALPHABET, prefix='', cores=1): ''' Return all password permutations of specified length that are in hashes by concurrently subsets of permutations concurrently. ''' # TODO: Create generator expression with arguments to pass to whack and # then use ProcessPoolExecutor to apply whack to all items in expression. return [] # Main Execution def main(): arguments = sys.argv[1:] alphabet = ALPHABET cores = 1 hashes_path = 'hashes.txt' length = 1 prefix = '' # TODO: Parse command line arguments # TODO: Load hashes set # TODO: Execute crack or smash function # TODO: Print all found passwords if __name__ == '__main__': main() # vim: set sts=4 sw=4 ts=8 expandtab ft=python: