X-Git-Url: https://git.njae.me.uk/?a=blobdiff_plain;f=cipher%2Fkeyword_cipher.py;h=20281828030a550948c433f246c8bc05a40622c1;hb=e670d7e12005cd73385f6c6251174a911ccc018b;hp=68c8904a6db9a19758d5e332c1374eaa27eb0382;hpb=311b300d197536622980f7a837294d8245e326b4;p=cipher-tools.git diff --git a/cipher/keyword_cipher.py b/cipher/keyword_cipher.py index 68c8904..2028182 100644 --- a/cipher/keyword_cipher.py +++ b/cipher/keyword_cipher.py @@ -1,8 +1,9 @@ -from utilities import * -from language_models import * from enum import Enum # from itertools import starmap import multiprocessing +import math +from support.utilities import * +from support.language_models import * from logger import logger @@ -193,13 +194,23 @@ def simulated_annealing_break(message, workers=10, worker_args = [] ciphertext = sanitise(message) for i in range(workers): - if not plain_alphabet: - plain_alphabet = string.ascii_lowercase - if not cipher_alphabet: - cipher_alphabet = list(string.ascii_lowercase) - random.shuffle(cipher_alphabet) - cipher_alphabet = cat(cipher_alphabet) - worker_args.append((ciphertext, plain_alphabet, cipher_alphabet, + if plain_alphabet is None: + used_plain_alphabet = string.ascii_lowercase + else: + used_plain_alphabet = plain_alphabet + if cipher_alphabet is None: + used_cipher_alphabet = list(string.ascii_lowercase) + random.shuffle(used_cipher_alphabet) + used_cipher_alphabet = cat(used_cipher_alphabet) + else: + used_cipher_alphabet = cipher_alphabet + # if not plain_alphabet: + # plain_alphabet = string.ascii_lowercase + # if not cipher_alphabet: + # cipher_alphabet = list(string.ascii_lowercase) + # random.shuffle(cipher_alphabet) + # cipher_alphabet = cat(cipher_alphabet) + worker_args.append((ciphertext, used_plain_alphabet, used_cipher_alphabet, initial_temperature, max_iterations, fitness)) with multiprocessing.Pool() as pool: breaks = pool.starmap(simulated_annealing_break_worker,