ch27.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:matasano 作者: shainer 项目源码 文件源码
def encrypt(self, plaintext):
        """CBC encryption."""
        cipher = AES.new(key=self._key, mode=AES.MODE_ECB)

        # The full URL is not necessary for this setup, so I am just encrypting
        # the plaintext as it is. I don't even need to support padding.
        prev_ct = self._iv
        block_index = 0
        ciphertext = b''

        # The loop simulates encryption through AES in CBC mode.
        while block_index < len(plaintext):
            block = plaintext[block_index : block_index + AES.block_size]
            final_block = strxor(block, prev_ct)

            cipher_block = cipher.encrypt(final_block)
            prev_ct = cipher_block
            ciphertext += cipher_block

            block_index += AES.block_size

        return ciphertext
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号