Rating:

We are given a couple of files: a python script, a text file, and a png(which is useless).

**main.py**

```python
from Crypto.Util.number import bytes_to_long

q = 64

flag = open("flag.txt", "rb").read()
flag_int = bytes_to_long(flag)

secret_key = []
while flag_int:
secret_key.append(flag_int % q)
flag_int //= q

print(f"{secret_key = }")
```

**out.txt**

```text
secret_key = [10, 52, 23, 14, 52, 16, 3, 14, 37, 37, 3, 25, 50, 32, 19, 14, 48, 32, 35, 13, 54, 12, 35, 12, 31, 29, 7, 29, 38, 61, 37, 27, 47, 5, 51, 28, 50, 13, 35, 29, 46, 1, 51, 24, 31, 21, 54, 28, 52, 8, 54, 30, 38, 17, 55, 24, 41, 1]
```

`secret_key` is the output of `main.py` and it's little tricky but pretty simple to reverse. What's happening is the flag is read from a file, the string is converted into an integer. The values for `secret_key` are generated by taking the 64 modulo of the integer, spitting that into `secret_key`, and then doing floor division (<https://www.geeksforgeeks.org/floor-division-in-python/>) on the integer, and repeating the operation until the integer is 0.

We can write a simple python script to reverse this operation by iterating through the values of `secret_key` by setting an accumulator integer to 0, and repeat multiplying it by 64, and then adding the current value in `secret_key`. The one tricky part is that `secret_key` must be iterated in reverse. That gives us the following solution script.

**solution.py**

```python
from Crypto.Util.number import long_to_bytes

secret_key = [10, 52, 23, 14, 52, 16, 3, 14, 37, 37, 3, 25, 50, 32, 19, 14, 48, 32, 35, 13, 54, 12, 35, 12, 31, 29, 7, 29, 38, 61, 37, 27, 47, 5, 51, 28, 50, 13, 35, 29, 46, 1, 51, 24, 31, 21, 54, 28, 52, 8, 54, 30, 38, 17, 55, 24, 41, 1]

out = 0

for num in secret_key[::-1]:
out *= 64
out += num

print(long_to_bytes(out).decode())
```

FLAG: `ictf{b4se_c0nv3rs1on_ftw_236680982d9e8449}`