def main(): parser = argparse.ArgumentParser(description="Caesar cipher solver") parser.add_argument('ciphertext', type=str, help='text to decipher') args = parser.parse_args() # Get every Caesar shift of the ciphertext shifts = [etao.caesar_shift(args.ciphertext, n) for n in range(26)] # Score each shift according to English character frequency. # Get tuples that pair the score with the text. scored_shifts = [(etao.score_text(shift), shift) for shift in shifts] # Sort by score, descending order scored_shifts.sort(reverse=True) # Print the top 3 results for result in scored_shifts[0:3]: print '"%s" (%02d%%)' % (result[1], int(result[0] * 100))
def test_shift_text_invalid_type(self): with self.assertRaises(TypeError): etao.caesar_shift(123, 0)
def test_shift_with_symbols(self): self.assertEqual(etao.caesar_shift('A. B!', 2), 'C. D!')
def test_shift_text_max(self): self.assertEqual(etao.caesar_shift('ABCD', 25), 'ZABC')
def test_shift_text_min(self): self.assertEqual(etao.caesar_shift('ABCD', 1), 'BCDE')