Beispiel #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)
Beispiel #2
0
 def test_encrypt(self):
     result = CBC.encrypt(self.y, self.key)
     print(result.hex())