> For the complete documentation index, see [llms.txt](https://h1dd3nc0d3.gitbook.io/h1dd3nc0d3/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://h1dd3nc0d3.gitbook.io/h1dd3nc0d3/qu3stc0nctf/reverse/twice-the-trouble.md).

# Twice the Trouble

بسم الله الرحمن الرحيم

<figure><img src="https://3895405999-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiVEVGRk7mlHY0zQOKM7W%2Fuploads%2Fb3PWTdyInmKmWBmgOSu5%2FScreenshot%202024-10-22%20131257.png?alt=media&amp;token=0100c5e9-7f09-426b-b485-5ceb42d9096e" alt=""><figcaption><p>challenge</p></figcaption></figure>

<figure><img src="https://3895405999-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiVEVGRk7mlHY0zQOKM7W%2Fuploads%2Fr8pUrRdomK4HAwyI96bo%2FScreenshot%202024-10-22%20131427.png?alt=media&amp;token=e15dcf2f-a2e8-4309-ad2a-665d0961216e" alt=""><figcaption></figcaption></figure>

In this challenge, we are provided with a Python script that encrypts a flag using the XOR operation. The task is to decipher the flag by satisfying a mathematical condition based on user input.

### Let's analyze the code

The provided Python script consists of several functions:

1.

```
**`xor_encrypt_decrypt(input_str, key)`**:
```

```
* This function performs the XOR operation on each character of the input string using a given key.
```

2\.

```
**`get_flag()`**:

* This function contains the encoded flag represented as a list of integers. It uses an XOR key (13) to decode the flag and returns it.
```

3\.

```
**`compare_numbers(num1, num2)`**:

* This function compares the magnitudes of two numbers. It checks if the absolute value of the first number is exactly twice the absolute value of the second number.
```

4\.

```
**`main()`**:

* The entry point of the program. It generates random numbers, takes user input for two numbers, and calls the `compare_numbers` function. If the comparison is successful, it reveals the flag.
```

### Solving the Challenge

To successfully retrieve the flag, we need to provide two numbers (`num1` and `num2`) such that: abs(num1)=2×abs(num2)\text{abs(num1)} = 2 \times \text{abs(num2)}abs(num1)=2×abs(num2)

For example, if we choose:

* **num1 = 10**
* **num2 = 5**

This satisfies the condition since `10 = 2 * 5`.

### Flag Retrieval

When the condition is met, the program will call `get_flag()`, which returns the decoded flag.

####

<figure><img src="https://3895405999-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiVEVGRk7mlHY0zQOKM7W%2Fuploads%2FWeBKMu1oAH4pELayrVH8%2FScreenshot%202024-10-22%20132406.png?alt=media&amp;token=af29315d-7579-40be-ae78-6ba13d52da95" alt=""><figcaption></figcaption></figure>

### Flag

```
QUESTCON{d0ubl3_tr0ubl3}
```
