Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def crack(ciphertext, iv):
- result = b''
- for b in range(0, len(ciphertext), block_size):
- block = ciphertext[b:b+block_size]
- previous_block = ciphertext[b-block_size:b] if b != 0 else iv
- suffix = b''
- for i in range(block_size):
- for byte in range(1, 256):
- padding = xor_bytes(suffix, bytes(len(suffix) * [i+1]))
- xor_block = bytes([0] * (block_size - len(padding) - 1)) + bytes([byte]) + padding
- if padding_oracle(block, xor_bytes(previous_block, xor_block)):
- suffix = bytes([(i+1) ^ byte]) + suffix
- break
- else:
- suffix = bytes([i+1]) + suffix
- result += suffix
- return unpad(result)
Add Comment
Please, Sign In to add comment