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 :)
评论列表
文章目录