Unlock the Encrypted Flag
بسم الله الرحمن الرحيم


In this challenge, we are provided with a Python script that encrypts a flag using the XOR operation and requires a specific password to reveal the flag. The goal is to bypass the password check and decrypt the flag.
Let's analyze the code
The script consists of the following main components:
str_xor(secret, key):This function performs an XOR operation between a secret string and a key. It generates a new key by repeating the original key until it matches the length of the secret.
Encrypted Flag:
The flag is stored in a file named
flag.txt.enc, which is read as binary data.
Password Check:
The
level_1_pw_check()function prompts the user for a password. The correct password is constructed from several parts and must start with "ak" and end with "9000". It also checks if the length of the entered password matches the obfuscated password.
Exploiting the Challenge
To successfully retrieve the flag:
We need to provide the correct password:
"ak98-=90adfjhgj321sleuth9000".The
str_xorfunction is then called with the encrypted flag and the key"utilitarian"to decrypt it.
Flag Retrieval
Upon entering the correct password, the program decrypts the flag using the XOR operation, revealing the hidden flag.

str_xor Function:
Inputs:
secret: The encrypted text (the flag).key: The key used for encryption (in this case, "utilitarian").
Process:
A new key (
new_key) is initialized with the value ofkey.A
whileloop is used to extend thenew_keyuntil its length matches that ofsecret.Characters from
keyare appended tonew_keybased on the indexi.When the end of the
keyis reached,iis reset to zero using(i + 1) % len(key).
Encryption/Decryption:
The XOR operation is applied between each character of the
secretand the generatednew_key.The
zipfunction is used to pair characters fromsecretandnew_key.Each pair of characters is converted to ASCII values, and the XOR operation is performed.
The results are converted back to characters using
chrand joined into a string.
Decrypting the Flag:
The flag is decrypted by calling the
str_xorfunction with the encrypted contentflag_encand the key"utilitarian".The encrypted text is converted from bytes to a string using
decode()before passing it to the function.

Flag
Last updated