Tags: limited1 crypto 

Rating:

# Limited 1

> Author: catgut6675

> Description: It's pretty easy to find random integers if you know the seed, but what if every second has a different seed?

[chal_time.py](https://github.com/nopedawn/CTF/blob/main/WolvCTF24/Limited1/chal_time.py)

```python {title="chal_time.py" lineNos=true lineNoStart=1}
import time
import random
import sys

if __name__ == '__main__':
flag = input("Flag? > ").encode('utf-8')
correct = [189, 24, 103, 164, 36, 233, 227, 172, 244, 213, 61, 62, 84, 124, 242, 100, 22, 94, 108, 230, 24, 190, 23, 228, 24]
time_cycle = int(time.time()) % 256
if len(flag) != len(correct):
print('Nope :(')
sys.exit(1)
for i in range(len(flag)):
random.seed(i+time_cycle)
if correct[i] != flag[i] ^ random.getrandbits(8):
print('Nope :(')
sys.exit(1)
print(flag)
```

The given Python script that uses the current time as a seed for the random number generator. The script then checks if the XOR of each character in the flag with a random 8-bit number equals the corresponding number in the `correct` list. If all checks pass, the flag is printed.

To do that, we need to reverse the process. Here's the solver:

```python {title="solver.py" lineNos=true lineNoStart=1}
import random

correct = [189, 24, 103, 164, 36, 233, 227, 172, 244, 213, 61, 62, 84, 124, 242, 100, 22, 94, 108, 230, 24, 190, 23, 228, 24]

for time_cycle in range(256):
flag = ""
for i in range(len(correct)):
random.seed(i+time_cycle)
char = correct[i] ^ random.getrandbits(8)
flag += chr(char)

if all(' ' <= c <= '~' for c in flag):
print(f"time_cycle: {time_cycle}\nflag: {flag} ")
```

```bash
$ python3 solver.py
time_cycle: 188
flag: wctf{f34R_0f_m1ss1ng_0ut}
```


> Flag: `wctf{f34R_0f_m1ss1ng_0ut}`

Original writeup (https://nopedawn.github.io/posts/ctfs/2024/wolv-ctf-2024/#limited-1).