def detect_xor(file_name): f = open(file_name, 'r') d = {} for line in f: line = line.rstrip().lstrip() candidate = decryptor.search_single_byte_xor_key(line) if candidate is None: continue freq = decryptor.analyze_char_freq(candidate) score = decryptor.score_char_freq(freq) d[score] = candidate return d[min(d)]
def test_search_single_byte_xor_key(self): key, message = decryptor.search_single_byte_xor_key('1b37373331363f78151b7f2b783431333d78397828372d363c78373e783a393b3736') self.assertEqual(message, "Cooking MC's like a pound of bacon") self.assertEqual(decryptor.search_single_byte_xor_key('0e3647e8592d35514a081243582536ed3de6734059001e3f535ce6271032'), None)