示例#1
0
    def test_zfill(self):
        cipher_obj = Rijndael(Bytes(0x8000000000000000).zfill(16))
        plaintext = Bytes(b'').zfill(16)
        ciphertext1 = cipher_obj.encrypt(plaintext)
        ciphertext2 = cipher_obj.decrypt(plaintext)

        self.assertEqual(cipher_obj.decrypt(ciphertext1), plaintext)
        self.assertEqual(cipher_obj.encrypt(ciphertext2), plaintext)
示例#2
0
    def _run_test(self, key, plaintext, block_size, test_vector, iterations=1):
        rijndael = Rijndael(key, block_size=block_size)

        to_enc = plaintext
        for _ in range(iterations):
            to_enc = rijndael.encrypt(to_enc)

        cipherhex = codecs.encode(to_enc, 'hex_codec')
        self.assertEqual(cipherhex, test_vector)

        to_dec = to_enc
        for _ in range(iterations):
            to_dec = rijndael.decrypt(to_dec)

        self.assertEqual(plaintext, to_dec)