lines = [] with open("25.input") as f: for line in f.readlines(): lines.append(int(line)) subject = 7 def crack_key(public_key): value = 1 for i in range(1, 1000000000): value *= subject value %= 20201227 if value == public_key: return i return None def generate_key(subject, loop_size): value = 1 for i in range(0, loop_size): value *= subject value %= 20201227 return value loop_sizes = [crack_key(line) for line in lines] print(loop_sizes) print(generate_key(lines[0], loop_sizes[1]))