Пример #1
0
    def test_cbc(self):
        key = bytes.fromhex("00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00")
        #1
        input = bytes.fromhex(
            "07 92 3A 39 EB 0A 81 7D 1C 4D 87 BD B8 2D 1F 1C "
            "48 CD 64 19 80 96 72 D2 34 92 60 D8 9A 08")
        encrypt = CBC.encrypt(input, key)
        decrypt = CBC.decrypt(encrypt, key)
        print("#1")
        print("input -           {0}".format(input.hex()))
        print("encrypt -         {0}".format(encrypt.hex()))
        print("expected_result - {0}".format(decrypt.hex()))
        print("actual_result -   {0}".format(input.hex()))
        print()

        # 2
        input = bytes.fromhex(
            "07 92 3A 39 EB 0A 81 7D 1C 4D 87 BD B8 2D 1F 1C "
            "48 CD 64 19 80 96 72 D2 34 92 60 D8 9A 08 00 01")
        encrypt = CBC.encrypt(input, key)
        decrypt = CBC.decrypt(encrypt, key)
        print("#2")
        print("input -           {0}".format(input.hex()))
        print("encrypt -         {0}".format(encrypt.hex()))
        print("expected_result - {0}".format(decrypt.hex()))
        print("actual_result -   {0}".format(input.hex()))
        print()

        # 3
        input = bytes.fromhex(
            "07 92 3A 39 EB 0A 81 7D 1C 4D 87 BD B8 2D 1F 1C "
            "48 CD 64 19 80 96 72 D2 34 92 60 D8 9A 08 00 01 "
            "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
            "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00")
        encrypt = CBC.encrypt(input, key)
        decrypt = CBC.decrypt(encrypt, key)
        print("#3")
        print("input -           {0}".format(input.hex()))
        print("encrypt -         {0}".format(encrypt.hex()))
        print("expected_result - {0}".format(decrypt.hex()))
        print("actual_result -   {0}".format(input.hex()))
        print()

        # 4
        input = bytes.fromhex(
            "07 92 3A 39 EB 0A 81 7D 1C 4D 87 BD B8 2D 1F 1C "
            "48 CD 64 19 80 96 72 D2 34 92 60 D8 9A 08 00 02 "
            "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00")
        encrypt = CBC.encrypt(input, key)
        decrypt = CBC.decrypt(encrypt, key)
        print("#4")
        print("input -           {0}".format(input.hex()))
        print("encrypt -         {0}".format(encrypt.hex()))
        print("expected_result - {0}".format(decrypt.hex()))
        print("actual_result -   {0}".format(input.hex()))
        print()

        self.assertTrue(True)
Пример #2
0
 def test_decrypt(self):
     x = bytes.fromhex(
         "07923a39eb0a817d1c4d87bdb82d1f1c4f5f5e206b9cf3af28dfe76522251f1d4f5f5e206b9cf3af28dfe76522251f1d4f5f5e206b9cf3af28dfe76522251f1d"
     )
     result = CBC.decrypt(x, self.key)
     print(result.hex())