test_rfc1751.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #
  2. # Test script for Cryptodome.Util.RFC1751.
  3. #
  4. # Part of the Python Cryptography Toolkit
  5. #
  6. # Written by Andrew Kuchling and others
  7. #
  8. # ===================================================================
  9. # The contents of this file are dedicated to the public domain. To
  10. # the extent that dedication to the public domain is not available,
  11. # everyone is granted a worldwide, perpetual, royalty-free,
  12. # non-exclusive license to exercise all rights associated with the
  13. # contents of this file for any purpose whatsoever.
  14. # No rights are reserved.
  15. #
  16. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  17. # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  18. # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  19. # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  20. # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  21. # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  22. # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  23. # SOFTWARE.
  24. # ===================================================================
  25. __revision__ = "$Id$"
  26. import binascii
  27. import unittest
  28. from Cryptodome.Util import RFC1751
  29. from Cryptodome.Util.py3compat import *
  30. test_data = [('EB33F77EE73D4053', 'TIDE ITCH SLOW REIN RULE MOT'),
  31. ('CCAC2AED591056BE4F90FD441C534766',
  32. 'RASH BUSH MILK LOOK BAD BRIM AVID GAFF BAIT ROT POD LOVE'),
  33. ('EFF81F9BFBC65350920CDD7416DE8009',
  34. 'TROD MUTE TAIL WARM CHAR KONG HAAG CITY BORE O TEAL AWL')
  35. ]
  36. class RFC1751Test_k2e (unittest.TestCase):
  37. def runTest (self):
  38. "Check converting keys to English"
  39. for key, words in test_data:
  40. key=binascii.a2b_hex(b(key))
  41. self.assertEqual(RFC1751.key_to_english(key), words)
  42. class RFC1751Test_e2k (unittest.TestCase):
  43. def runTest (self):
  44. "Check converting English strings to keys"
  45. for key, words in test_data:
  46. key=binascii.a2b_hex(b(key))
  47. self.assertEqual(RFC1751.english_to_key(words), key)
  48. # class RFC1751Test
  49. def get_tests(config={}):
  50. return [RFC1751Test_k2e(), RFC1751Test_e2k()]
  51. if __name__ == "__main__":
  52. unittest.main()