Aedquate Encryption Standard
Description
Files
This seems like a custom AES implementation. Note that we are not provided a decryption routine, so lets simply write one.
Implementing one is not too complicated, one just need to reverse the encrypt function step by step.
Its essentially the encrypt function in reverse, in encrypt, key is xored at last in the for loop, we do it first.
Then we do reverse of permutation dec_perm and reverse of substitution dec_sub in the following functions.
For reversing enc_sub, we just need to find the index of corresponding byte in the sbox
To reverse the permutation,
Once we have decryption function set up, we can start exploring the challenge :)
The devil at work here is the expand_key function. One could easily verify that without using much brain :)
Without even looking at the key_expansion, one could say the keys it expands to are quite bad and possibly quite repetitive.
Voila, lets try randomly decrypting with a key.
One could aready read a lot of the flag! We only lack the first two blocks of the flag.
Why can we read the rest of the flag by decrypting with some non-sense key?
Since in encrypt function each block is xored with the key byte at the corresponding position, we luckily end up encrypting it with byte b'\x01' for the last 6 bytes.
And xoring with b'\x01' would be the same byte again hehe.
But wouldnt it be lost amidst all the permutation and substitution??
No, since we are exactly reversing the permutation and substitution since the xor part dies out!
Why do we have so many 0’s and 1’s in the expanded key?
It is evident from this part
As cur is repeteadly raised to the power num, once cur hits 0 or 1, it will stay 0 or 1 out of its misery.
So all we need to figure out is the first two bytes, which should be quite easy!
Ugly solution in solve.py
And boom! we have our flag