test_rfc1751.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import unittest
  2. import binascii
  3. from Cryptodome.Util.RFC1751 import key_to_english, english_to_key
  4. class RFC1751_Tests(unittest.TestCase):
  5. def test1(self):
  6. data = [
  7. ('EB33F77EE73D4053', 'TIDE ITCH SLOW REIN RULE MOT'),
  8. ('CCAC2AED591056BE4F90FD441C534766', 'RASH BUSH MILK LOOK BAD BRIM AVID GAFF BAIT ROT POD LOVE'),
  9. ('EFF81F9BFBC65350920CDD7416DE8009', 'TROD MUTE TAIL WARM CHAR KONG HAAG CITY BORE O TEAL AWL')
  10. ]
  11. for key_hex, words in data:
  12. key_bin = binascii.a2b_hex(key_hex)
  13. w2 = key_to_english(key_bin)
  14. self.assertEqual(w2, words)
  15. k2 = english_to_key(words)
  16. self.assertEqual(k2, key_bin)
  17. def test_error_key_to_english(self):
  18. self.assertRaises(ValueError, key_to_english, b'0' * 7)
  19. def get_tests(config={}):
  20. from Cryptodome.SelfTest.st_common import list_test_cases
  21. tests = list_test_cases(RFC1751_Tests)
  22. return tests
  23. if __name__ == '__main__':
  24. suite = lambda: unittest.TestSuite(get_tests())
  25. unittest.main(defaultTest='suite')