I understand my main limitation is my computer's ability to compare millions of combinations but I wondered if there is any way to improve the speed at which the comparisons take place.
My code is as follows:
code = open("C:\\Users\\User\\Desktop\\code.txt").read()
dictionary = open("C:\\Users\\User\\Desktop\\dictionary.txt").read()
precomputed = open("C:\\Users\\User\\Desktop\\precompute.txt").read()
code_found = False
from timeit import default_timer as timer
import itertools
printable = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' #"!"#$%&\'()*+,-./:;<=>?@[\]^_`{|}~'
This sets out the file locations including the file where the 'password' is (named code).
Precomputed is a list of all combinations Printable can make saved to a .txt file:
def bruteforce_by_precomputed():
    code_found = False
    start=timer()
    for attempt in precompute.splitlines():
        if attempt == code:
            print("the word is", attempt)
            code_found = True
            break
        #if attempt != code:
            #print(attempt, "not word")
    if code_found != True:
        print("word not in dictionary") 
    end = timer()
    taken = (end-start)
    print("time taken =  :", taken)
This section is comparing each precomputed value within the .txt file to check if it matches the code:
def dictionary_attack():
    for attempt in dictionary.splitlines():
        if attempt == code:
            print("the word is", attempt)
            code_found = True
            break
        #if attempt != code:
            #print(attempt, "not word")
    if code_found != True:
        print("word not in dictionary")
This section uses a .txt file with every English word for a match:
def infinately_increasing_brute():    
    import itertools
    lengthoforce = 0
    while attempt != code:
        lengthoforce += 1
        for brute_attempt in itertools.product(printable, repeat = lengthoforce):
            attempt = ''.join(brute_attempt)
            if attempt == code:
                print("succesful brute, your word is: ", attempt)
                break
This section uses .product from itertools to find every combination of Printable and if not found increase the length of combination by 1:
def custom_brute():
    lengthoforce = int(input("what length to force?"))
    start = timer()
    for brute_attempt in itertools.product(printable, repeat = lengthoforce):
        attempt = ''.join(brute_attempt)
        if attempt == code:
            print("")
            print("succesful brute, your word is: ", attempt)
            print("")
            end = timer()
            print(end-start, "seconds were taken to find", attempt)
            print("")
            break
This section simply allows the user to enter the length of the combinations to compare.
I have another section of code which creates all possible combinations and saves them to a .txt file. Instead of generating possibilities, it just reads and compares, but I would like to avoid this and generate combinations and compare.