Unlock the Encrypted Flag
بسم الله الرحمن الرحيم
Last updated
بسم الله الرحمن الرحيم
Last updated
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.
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.
To successfully retrieve the flag:
We need to provide the correct password: "ak98-=90adfjhgj321sleuth9000"
.
The str_xor
function is then called with the encrypted flag and the key "utilitarian"
to decrypt it.
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 of key
.
A while
loop is used to extend the new_key
until its length matches that of secret
.
Characters from key
are appended to new_key
based on the index i
.
When the end of the key
is reached, i
is reset to zero using (i + 1) % len(key)
.
Encryption/Decryption:
The XOR operation is applied between each character of the secret
and the generated new_key
.
The zip
function is used to pair characters from secret
and new_key
.
Each pair of characters is converted to ASCII values, and the XOR operation is performed.
The results are converted back to characters using chr
and joined into a string.
Decrypting the Flag:
The flag is decrypted by calling the str_xor
function with the encrypted content flag_enc
and the key "utilitarian"
.
The encrypted text is converted from bytes to a string using decode()
before passing it to the function.