Esempio n. 1
0
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))
Esempio n. 2
0
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))
Esempio n. 3
0
 def test_shift_text_invalid_type(self):
     with self.assertRaises(TypeError):
         etao.caesar_shift(123, 0)
Esempio n. 4
0
 def test_shift_with_symbols(self):
     self.assertEqual(etao.caesar_shift('A. B!', 2), 'C. D!')
Esempio n. 5
0
 def test_shift_text_max(self):
     self.assertEqual(etao.caesar_shift('ABCD', 25), 'ZABC')
Esempio n. 6
0
 def test_shift_text_min(self):
     self.assertEqual(etao.caesar_shift('ABCD', 1), 'BCDE')
Esempio n. 7
0
 def test_shift_text_invalid_type(self):
     with self.assertRaises(TypeError):
         etao.caesar_shift(123, 0)
Esempio n. 8
0
 def test_shift_with_symbols(self):
     self.assertEqual(etao.caesar_shift('A. B!', 2), 'C. D!')
Esempio n. 9
0
 def test_shift_text_max(self):
     self.assertEqual(etao.caesar_shift('ABCD', 25), 'ZABC')
Esempio n. 10
0
 def test_shift_text_min(self):
     self.assertEqual(etao.caesar_shift('ABCD', 1), 'BCDE')