diff --git a/src/mono/break_mono.py b/src/mono/break_mono.py index a362a8f..a1f94c2 100644 --- a/src/mono/break_mono.py +++ b/src/mono/break_mono.py @@ -62,6 +62,9 @@ class Breaker(): @staticmethod def match_ciphertext(text: str, word_pos: tuple, char: tuple): + """ + asdf + """ word, wposl = word_pos wpos = wposl[0] wlen = len(word) @@ -76,6 +79,19 @@ class Breaker(): return snip_count.most_common(1)[0][0] + @staticmethod + def choose_known_letters(key_alphabet): + letters = list(key_alphabet.keys()) + if len(key_alphabet) < 3: + yield letters + else: + for i in letters: + for j in letters: + for k in letters: + if k == j or k == i or j == i: continue + yield [i, j, k] + return None + def __init__(self, ciphertext, word_file): self.ciphertext = ciphertext self.alph = self.derive_alphabet_freq(self.get_frequency(ciphertext)) @@ -84,23 +100,28 @@ class Breaker(): def get_key(self): - + key_alphabet = OrderedDict() # most frequent char in English and corresponding most common char in text - #most_freq = self.alph.popitem(last=False) - most_freq = next(iter(self.alph)) - word_pos = Breaker.get_word_containing( - self.word_file, - #most_freq[0] - most_freq - ) - most_common = Breaker.match_ciphertext( - self.ciphertext, - word_pos, - most_freq - ) - - print("most_freq", most_freq, "word_pos:", word_pos, "most_common:", most_common) + most_freq = self.alph[Breaker.EN_LETTER_FREQ] + + key_alphabet[Breaker.EN_LETTER_FREQ[0]] = most_freq + + while len(key_alphabet) < 26: + + word_pos = Breaker.get_word_containing( + self.word_file, + next(Breaker.choose_known_letters(key_alphabet)) + ) + + pass + + most_common = Breaker.match_ciphertext( + self.ciphertext, + word_pos, + most_freq + ) + pass ## end Breaker