Как можно ускорить данный код
Данный код дешифрует шифр путем подбора ключа и сравнивая с словарем на 500.000 слов. ключ может быть 9 значным а для того чтобы дойти хотя бы до 8 значных надо целый час что достаточно долго. Как можно ускорить ?
import string
import numpy as np
import nuitka
from numba import njit, prange
import time
string.digits + string.ascii_letters + string.punctuation + string.digits
alph = string.ascii_uppercase
# print(encrypt('ANCIENT', '420')) #шифрование
# print(decrypt('NHUDMOVUHB', '13')) #расшифровывание
def algo(text, k, op):
k *= len(text) // len(k) + 1
return ''.join(alph[alph.index(j) + int(k[i]) * op] for i, j in enumerate(text))
def decrypt(message, key):
return algo(message, key, -1)
def encrypt(message, key):
return algo(message, key, 1)
word_toDecode = 'Epqv'.upper()
f = open('words.txt')
dictionary = f.readlines()
dictionary = set(word.strip().lower() for word in dictionary)
duplicate_words = []
def brute():
for x in prange(10000000):
s = decrypt(word_toDecode, str(x))
if s.lower() in dictionary:
for i in duplicate_words:
if i == s.lower(): break
else:
duplicate_words.append(s.lower())
print(s + ' Key - ' + str(x))
def start():
cur_time = time.time()
brute()
end_time = time.time()
print(end_time - cur_time)
f.close()
start()