PageRenderTime 57ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/contrib/pycrypto/lib/Crypto/SelfTest/Cipher/test_Blowfish.py

https://gitlab.com/Smileyt/KomodoEdit
Python | 112 lines | 78 code | 7 blank | 27 comment | 1 complexity | 8796fb2f10a1d0a6b2de979bd05d9256 MD5 | raw file
  1. # -*- coding: utf-8 -*-
  2. #
  3. # SelfTest/Cipher/test_Blowfish.py: Self-test for the Blowfish cipher
  4. #
  5. # Written in 2008 by Dwayne C. Litzenberger <dlitz@dlitz.net>
  6. #
  7. # ===================================================================
  8. # The contents of this file are dedicated to the public domain. To
  9. # the extent that dedication to the public domain is not available,
  10. # everyone is granted a worldwide, perpetual, royalty-free,
  11. # non-exclusive license to exercise all rights associated with the
  12. # contents of this file for any purpose whatsoever.
  13. # No rights are reserved.
  14. #
  15. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  18. # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  19. # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  20. # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  21. # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  22. # SOFTWARE.
  23. # ===================================================================
  24. """Self-test suite for Crypto.Cipher.Blowfish"""
  25. __revision__ = "$Id$"
  26. # This is a list of (plaintext, ciphertext, key) tuples.
  27. test_data = [
  28. # Test vectors from http://www.schneier.com/code/vectors.txt
  29. ('0000000000000000', '4ef997456198dd78', '0000000000000000'),
  30. ('ffffffffffffffff', '51866fd5b85ecb8a', 'ffffffffffffffff'),
  31. ('1000000000000001', '7d856f9a613063f2', '3000000000000000'),
  32. ('1111111111111111', '2466dd878b963c9d', '1111111111111111'),
  33. ('1111111111111111', '61f9c3802281b096', '0123456789abcdef'),
  34. ('0123456789abcdef', '7d0cc630afda1ec7', '1111111111111111'),
  35. ('0000000000000000', '4ef997456198dd78', '0000000000000000'),
  36. ('0123456789abcdef', '0aceab0fc6a0a28d', 'fedcba9876543210'),
  37. ('01a1d6d039776742', '59c68245eb05282b', '7ca110454a1a6e57'),
  38. ('5cd54ca83def57da', 'b1b8cc0b250f09a0', '0131d9619dc1376e'),
  39. ('0248d43806f67172', '1730e5778bea1da4', '07a1133e4a0b2686'),
  40. ('51454b582ddf440a', 'a25e7856cf2651eb', '3849674c2602319e'),
  41. ('42fd443059577fa2', '353882b109ce8f1a', '04b915ba43feb5b6'),
  42. ('059b5e0851cf143a', '48f4d0884c379918', '0113b970fd34f2ce'),
  43. ('0756d8e0774761d2', '432193b78951fc98', '0170f175468fb5e6'),
  44. ('762514b829bf486a', '13f04154d69d1ae5', '43297fad38e373fe'),
  45. ('3bdd119049372802', '2eedda93ffd39c79', '07a7137045da2a16'),
  46. ('26955f6835af609a', 'd887e0393c2da6e3', '04689104c2fd3b2f'),
  47. ('164d5e404f275232', '5f99d04f5b163969', '37d06bb516cb7546'),
  48. ('6b056e18759f5cca', '4a057a3b24d3977b', '1f08260d1ac2465e'),
  49. ('004bd6ef09176062', '452031c1e4fada8e', '584023641aba6176'),
  50. ('480d39006ee762f2', '7555ae39f59b87bd', '025816164629b007'),
  51. ('437540c8698f3cfa', '53c55f9cb49fc019', '49793ebc79b3258f'),
  52. ('072d43a077075292', '7a8e7bfa937e89a3', '4fb05e1515ab73a7'),
  53. ('02fe55778117f12a', 'cf9c5d7a4986adb5', '49e95d6d4ca229bf'),
  54. ('1d9d5c5018f728c2', 'd1abb290658bc778', '018310dc409b26d6'),
  55. ('305532286d6f295a', '55cb3774d13ef201', '1c587f1c13924fef'),
  56. ('0123456789abcdef', 'fa34ec4847b268b2', '0101010101010101'),
  57. ('0123456789abcdef', 'a790795108ea3cae', '1f1f1f1f0e0e0e0e'),
  58. ('0123456789abcdef', 'c39e072d9fac631d', 'e0fee0fef1fef1fe'),
  59. ('ffffffffffffffff', '014933e0cdaff6e4', '0000000000000000'),
  60. ('0000000000000000', 'f21e9a77b71c49bc', 'ffffffffffffffff'),
  61. ('0000000000000000', '245946885754369a', '0123456789abcdef'),
  62. ('ffffffffffffffff', '6b5c5a9c5d9e0a5a', 'fedcba9876543210'),
  63. ('fedcba9876543210', 'f9ad597c49db005e', 'f0'),
  64. ('fedcba9876543210', 'e91d21c1d961a6d6', 'f0e1'),
  65. ('fedcba9876543210', 'e9c2b70a1bc65cf3', 'f0e1d2'),
  66. ('fedcba9876543210', 'be1e639408640f05', 'f0e1d2c3'),
  67. ('fedcba9876543210', 'b39e44481bdb1e6e', 'f0e1d2c3b4'),
  68. ('fedcba9876543210', '9457aa83b1928c0d', 'f0e1d2c3b4a5'),
  69. ('fedcba9876543210', '8bb77032f960629d', 'f0e1d2c3b4a596'),
  70. ('fedcba9876543210', 'e87a244e2cc85e82', 'f0e1d2c3b4a59687'),
  71. ('fedcba9876543210', '15750e7a4f4ec577', 'f0e1d2c3b4a5968778'),
  72. ('fedcba9876543210', '122ba70b3ab64ae0', 'f0e1d2c3b4a596877869'),
  73. ('fedcba9876543210', '3a833c9affc537f6', 'f0e1d2c3b4a5968778695a'),
  74. ('fedcba9876543210', '9409da87a90f6bf2', 'f0e1d2c3b4a5968778695a4b'),
  75. ('fedcba9876543210', '884f80625060b8b4', 'f0e1d2c3b4a5968778695a4b3c'),
  76. ('fedcba9876543210', '1f85031c19e11968', 'f0e1d2c3b4a5968778695a4b3c2d'),
  77. ('fedcba9876543210', '79d9373a714ca34f', 'f0e1d2c3b4a5968778695a4b3c2d1e'),
  78. ('fedcba9876543210', '93142887ee3be15c',
  79. 'f0e1d2c3b4a5968778695a4b3c2d1e0f'),
  80. ('fedcba9876543210', '03429e838ce2d14b',
  81. 'f0e1d2c3b4a5968778695a4b3c2d1e0f00'),
  82. ('fedcba9876543210', 'a4299e27469ff67b',
  83. 'f0e1d2c3b4a5968778695a4b3c2d1e0f0011'),
  84. ('fedcba9876543210', 'afd5aed1c1bc96a8',
  85. 'f0e1d2c3b4a5968778695a4b3c2d1e0f001122'),
  86. ('fedcba9876543210', '10851c0e3858da9f',
  87. 'f0e1d2c3b4a5968778695a4b3c2d1e0f00112233'),
  88. ('fedcba9876543210', 'e6f51ed79b9db21f',
  89. 'f0e1d2c3b4a5968778695a4b3c2d1e0f0011223344'),
  90. ('fedcba9876543210', '64a6e14afd36b46f',
  91. 'f0e1d2c3b4a5968778695a4b3c2d1e0f001122334455'),
  92. ('fedcba9876543210', '80c7d7d45a5479ad',
  93. 'f0e1d2c3b4a5968778695a4b3c2d1e0f00112233445566'),
  94. ('fedcba9876543210', '05044b62fa52d080',
  95. 'f0e1d2c3b4a5968778695a4b3c2d1e0f0011223344556677'),
  96. ]
  97. def get_tests(config={}):
  98. from Crypto.Cipher import Blowfish
  99. from common import make_block_tests
  100. return make_block_tests(Blowfish, "Blowfish", test_data)
  101. if __name__ == '__main__':
  102. import unittest
  103. suite = lambda: unittest.TestSuite(get_tests())
  104. unittest.main(defaultTest='suite')
  105. # vim:set ts=4 sw=4 sts=4 expandtab: