|  |  | @ -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)) |  |  |  | 
 | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         key_alphabet[Breaker.EN_LETTER_FREQ[0]] = most_freq | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         while len(key_alphabet) < 26: | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             word_pos = Breaker.get_word_containing( |  |  |  |             word_pos = Breaker.get_word_containing( | 
			
		
	
		
		
			
				
					
					|  |  |  |                 self.word_file, |  |  |  |                 self.word_file, | 
			
		
	
		
		
			
				
					
					|  |  |  |             #most_freq[0] |  |  |  |                 next(Breaker.choose_known_letters(key_alphabet)) | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             most_freq |  |  |  |  | 
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |             ) |  |  |  |             ) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             pass | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             most_common = Breaker.match_ciphertext( |  |  |  |             most_common = Breaker.match_ciphertext( | 
			
		
	
		
		
			
				
					
					|  |  |  |                 self.ciphertext, |  |  |  |                 self.ciphertext, | 
			
		
	
		
		
			
				
					
					|  |  |  |                 word_pos, |  |  |  |                 word_pos, | 
			
		
	
		
		
			
				
					
					|  |  |  |                 most_freq |  |  |  |                 most_freq | 
			
		
	
		
		
			
				
					
					|  |  |  |             ) |  |  |  |             ) | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         print("most_freq", most_freq, "word_pos:", word_pos, "most_common:", most_common) |  |  |  |         pass | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     ## end Breaker |  |  |  |     ## end Breaker | 
			
		
	
	
		
		
			
				
					|  |  | 
 |