fügt choose_known_letters hinzu. Vor rewrite match_ciphertext

breakmono2
Daniel Tschertkow 5 years ago
parent e3f854fa0c
commit 3331177041

@ -62,6 +62,9 @@ class Breaker():
@staticmethod @staticmethod
def match_ciphertext(text: str, word_pos: tuple, char: tuple): def match_ciphertext(text: str, word_pos: tuple, char: tuple):
"""
asdf
"""
word, wposl = word_pos word, wposl = word_pos
wpos = wposl[0] wpos = wposl[0]
wlen = len(word) wlen = len(word)
@ -76,6 +79,19 @@ class Breaker():
return snip_count.most_common(1)[0][0] 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): def __init__(self, ciphertext, word_file):
self.ciphertext = ciphertext self.ciphertext = ciphertext
self.alph = self.derive_alphabet_freq(self.get_frequency(ciphertext)) self.alph = self.derive_alphabet_freq(self.get_frequency(ciphertext))
@ -84,23 +100,28 @@ class Breaker():
def get_key(self): def get_key(self):
key_alphabet = OrderedDict()
# most frequent char in English and corresponding most common char in text # most frequent char in English and corresponding most common char in text
#most_freq = self.alph.popitem(last=False) most_freq = self.alph[Breaker.EN_LETTER_FREQ]
most_freq = next(iter(self.alph))
word_pos = Breaker.get_word_containing( key_alphabet[Breaker.EN_LETTER_FREQ[0]] = most_freq
self.word_file,
#most_freq[0] while len(key_alphabet) < 26:
most_freq
) word_pos = Breaker.get_word_containing(
most_common = Breaker.match_ciphertext( self.word_file,
self.ciphertext, next(Breaker.choose_known_letters(key_alphabet))
word_pos, )
most_freq
) pass
print("most_freq", most_freq, "word_pos:", word_pos, "most_common:", most_common) most_common = Breaker.match_ciphertext(
self.ciphertext,
word_pos,
most_freq
)
pass
## end Breaker ## end Breaker

Loading…
Cancel
Save