<jupyter_start><jupyter_text>Chellenge 5 Challenge 5.1<jupyter_code>myinput = '<PASSWORD>'
import hashlib

def md5hash(myinput):
    hasher = hashlib.md5()
    hasher.update(myinput.encode('utf-8'))
    return hasher.hexdigest()

def is_valid(myhash):
    lower_bound = int('0x' + '00000' + 'f'*27, 16)
    if int(myhash, 16) > lower_bound:
        return False
    else:
        return True

def password(myinput):
    i = 0
    j = 0
    pswd = ''
    while i < len(myinput):
        myhash = md5hash(myinput + str(j))
        if is_valid(myhash):
            pswd += myhash[5]
            i += 1
        j += 1
    return pswd
password(myinput)<jupyter_output><empty_output><jupyter_text>Challenge 5.2<jupyter_code>def complex_password(myinput):
    i = 0
    j = 0
    pswd = [None] * len(myinput)
    while i < len(myinput):
        myhash = md5hash(myinput + str(j))
        if is_valid(myhash):
            pos = int(myhash[5], 16)
            if (pos in range(len(myinput))) and (pswd[pos] is None):
                pswd[pos] = myhash[6]
                i += 1
        j += 1
    return ''.join(pswd)
complex_password(myinput)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1323024054982818, 'fraction_numerical': 0.03006872852233677, 'mean_word_length': 2.456973293768546, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '511168', 'license': 'MIT', 'n_tokens_mistral': 460, 'n_tokens_neox': 428, 'n_words': 91, 'path': '2016/ferran/day5.ipynb', 'repo_name': 'bbglab/adventofcode', 'size': '1162'}