Created
May 13, 2017 09:51
-
-
Save mikeecb/b1c087a37ee750dfa446f3c7a4ce3f2e to your computer and use it in GitHub Desktop.
Cryptopals Set 2 Exercise 16 Simplified
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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