ch25.py 文件源码

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

项目:matasano 作者: shainer 项目源码 文件源码
def EditCTR(ciphertext, offset, newText, ctrObj):
    numBlocks = block_utils.GetNumBlocks(ciphertext)

    # Sanity checking.
    if offset < 0 or offset > numBlocks - 1:
        raise ValueError("Invalid offset.")

    if len(newText) != AES.block_size:
        raise ValueError("New plaintext must be 1 block in size")

    # Encrypt the new block of text using the value of the
    # counter for the 'offset' block of the ciphertext. The idea
    # is that newBlock will replace the block at position 'offset'
    # in the ciphertext, although here we do not perform the
    # actual substitution.
    newBlock = ctrObj.OneBlockCrypt(newText, offset)
    return newBlock

# This function is only here to recover the text as explained
# in the challenge. Of course here we need to know the key :)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号