Take Note: For this challenge, you need to have a rough understanding of how bitwise operation works.
We were given a Python file, with the FLAG variable as grey{...}
Therefore, we figured that we have to get the flag with the Python file given!
import secretsFLAG=b'grey{...}'assertlen(FLAG)==40key = secrets.token_bytes(4)defencrypt(m):returnbytes([x ^ y for x, y in zip(m,key)])c =b''for i inrange(0, len(FLAG),4): c +=encrypt(bytes(FLAG[i : i +4]))print(c.hex())# 982e47b0840b47a59c334facab3376a19a1b50ac861f43bdbc2e5bb98b3375a68d3046e8de7d03b4
There are a few things we took note of;
Key
Encrypt function
Flag
Hex output (commented out at the bottom of the code)
We were given the hex output, therefore we realized that we have to reverse the hex output in order to get the flag! π₯
The key variable tells us that the secret key is 4 bytes long.
Given the FLAG variable, we know that "grey" is the the first 4 characters.
The first 4 bytes of the hex output is 98 2e 47 b0
Encryptfunction showed x ^ y at the return statement, therefore, it is doing an XOR operation.
Given the information above, we deduced that x ^ y equals to grey ^ 982e47b0
import secrets
FLAG = bytes.fromhex('982e47b0840b47a59c334facab3376a19a1b50ac861f43bdbc2e5bb98b3375a68d3046e8de7d03b4')
key = bytes.fromhex('ff5c22c9')
def encrypt(m):
return bytes([x ^ y for x, y in zip(m,key)])
c = b''
for i in range(0, len(FLAG), 4):
print(c)
c += encrypt(bytes(FLAG[i : i + 4]))
print(c)