07. Transformation - PicoCTF 2021 Writeup

07. Transformation - PicoCTF 2021 Writeup

I wonder what this really is...

ยท

1 min read

Category: Reverse Engineering | Author: Madstacks | Points: 20

Hello All ๐Ÿ‘‹,

This is quite a straightforward one. If we download the file that is provided and open it, we get a bunch of Chinese characters. But why is there a bunch of Chinese characters in a CTF challenge? Well, this is actually an encrypted text. In the description we have a small Python code:

''.join([chr((ord(flag[i]) << 8) + ord(flag[i + 1])) for i in range(0, len(flag), 2)])

We see the variable flag in it, so we can assume that whatever this is doing, it takes in the flag as input and outputs some encrypted text. So obviously the person who made this challenge has used this to encrypt the flag and get the random Chinese characters we see.

So the most straightforward thing we can conclude is that we have to reverse whatever is being done by this code. First let's analyse what this code is doing.

Now we will write a new process that reverses the result of this action.

After coding this in Python, we get the following code.

string = '' # Include the encrypted text you got
output = ''

for i in range(len(string)):
    output += chr(ord(string[i])>>8) + chr((ord(string[i]))-((ord(string[i])>>8)<<8))

print(output)

Now when we run this code, voila, we get the flag back!

ย