Beispiel #1
0
 def test_score_digrams(self):
     self.assertEqual(
         etao.score_text('the the',
                         freq={
                             'th': 0.5, 'he': 0.5
                         }),
         1.0
         )
Beispiel #2
0
 def test_score_identical(self):
     self.assertEqual(
         etao.score_text('ABCD',
                         freq={
                             'a': 0.25,
                             'b': 0.25,
                             'c': 0.25,
                             'd': 0.25
                         }), 1.0)
Beispiel #3
0
 def test_score_identical(self):
     self.assertEqual(
         etao.score_text('ABCD',
                         freq={
                             'a': 0.25, 'b': 0.25,
                             'c': 0.25, 'd': 0.25
                         }),
         1.0
     )
Beispiel #4
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))
Beispiel #5
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))
Beispiel #6
0
 def test_score_invalid_table_case(self):
     with self.assertRaises(ValueError):
         etao.score_text('swag', freq={'ayyy': .2, 'LMaO': 0.3})
Beispiel #7
0
 def test_score_empty_table(self):
     with self.assertRaises(ValueError):
         etao.score_text('swag', freq={})
Beispiel #8
0
 def test_score_none(self):
     self.assertEqual(
         etao.score_text('zzzz', freq={'a': 1.0}),
         0.0
     )
Beispiel #9
0
 def test_score_invalid_table_case(self):
     with self.assertRaises(ValueError):
         etao.score_text('swag', freq={'ayyy': .2, 'LMaO': 0.3})
Beispiel #10
0
 def test_score_empty_table(self):
     with self.assertRaises(ValueError):
         etao.score_text('swag', freq={})
Beispiel #11
0
 def test_score_digrams(self):
     self.assertEqual(
         etao.score_text('the the', freq={
             'th': 0.5,
             'he': 0.5
         }), 1.0)
Beispiel #12
0
 def test_score_none(self):
     self.assertEqual(etao.score_text('zzzz', freq={'a': 1.0}), 0.0)