Skip to content

Instantly share code, notes, and snippets.

@mikeecb
Created May 13, 2017 09:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikeecb/b1c087a37ee750dfa446f3c7a4ce3f2e to your computer and use it in GitHub Desktop.
Save mikeecb/b1c087a37ee750dfa446f3c7a4ce3f2e to your computer and use it in GitHub Desktop.
Cryptopals Set 2 Exercise 16 Simplified
def crack():
first_block = bytearray('A' * AES.block_size)
second_block = bytearray("AadminAtrueA")
plaintext = first_block + second_block
ciphertext = encryption_oracle(plaintext)
# We 'know' the prefix is two blocks long
offset = 32
# Change the first byte in first_block 'A' so we change the first byte in
# second_block to be ';'
ciphertext[offset] = bytes(
xor(
bytearray(chr(ciphertext[offset])),
xor(bytearray("A"), bytearray(";"))
)
)
# Change the 7th byte in first_block 'A' so we change the first byte in
# second_block to be '='
ciphertext[offset + 6] = bytes(
xor(
bytearray(chr(ciphertext[offset + 6])),
xor(bytearray("A"), bytearray("="))
)
)
# Change the 12th byte in first_block 'A' so we change the first byte in
# second_block to be ';'
ciphertext[offset + 11] = bytes(
xor(
bytearray(chr(ciphertext[offset + 11])),
xor(bytearray("A"), bytearray(";"))
)
)
return is_admin(ciphertext)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment