import hashlib key = "iwrupvqb" found = False i = 0 while not found: result = hashlib.md5(bytes(key+str(i), 'utf-8')).hexdigest() i += 1 if result[:5] == "00000": found = True print(i-1)