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
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

Loading…
Cancel
Save