XOR Cryptography with Python | TryHackMe W1seGuy

XOR Cryptography with Python | TryHackMe W1seGuy

We solved a cryptography CTF challenge where XOR encryption and HEX encoding were used to encrypt and encode the challenge flag. We used Python to craft an XOR decryption statement to decrypt the first four characters of the flag, THM{, in order to find the decryption key. This was part of TryHackMe W1seGuy room.

Task Scenario

Yes, it’s me again with another crypto challenge!

Have a look at the source code before moving on to Task 2. You can review the source code by clicking on the Download Task Files button at the top of this task to download the required file.

Your friend told me you were wise, but I don’t believe them. Can you prove me wrong?

The server is listening on port 1337 via TCP. You can connect to it using Netcat or any other tool you prefer.

Understanding the python source code

Source code is below:

In the source code above, The  function will first generate a random key of length  as shown below:

And below is the call to the function setup

The  function takes the encryption key and uses  encryption on the first flag by iterating over all characters of the flag and ‘ing it with .

Lastly it applies  encoding on the result:

The lin below prints the  encrypted and  encoded flag returned from the  function.

Afterwards, it asks for the encryption key and reads the user input. If the  or the input provided matches the  randomly generated, the code the prints the second flag read from .

Check out the video below for detailed explanation.

Room Answers | TryHackMe W1seGuy

Room answers can be found here.

Video Walkthrough | TryHackMe W1seGuy

To view or add a comment, sign in

Others also viewed

Explore topics