Guest User

Untitled

a guest
Jul 22nd, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. def crack(ciphertext, iv):
  2. result = b''
  3. for b in range(0, len(ciphertext), block_size):
  4. block = ciphertext[b:b+block_size]
  5. previous_block = ciphertext[b-block_size:b] if b != 0 else iv
  6. suffix = b''
  7. for i in range(block_size):
  8. for byte in range(1, 256):
  9. padding = xor_bytes(suffix, bytes(len(suffix) * [i+1]))
  10. xor_block = bytes([0] * (block_size - len(padding) - 1)) + bytes([byte]) + padding
  11. if padding_oracle(block, xor_bytes(previous_block, xor_block)):
  12. suffix = bytes([(i+1) ^ byte]) + suffix
  13. break
  14. else:
  15. suffix = bytes([i+1]) + suffix
  16. result += suffix
  17. return unpad(result)
Add Comment
Please, Sign In to add comment