Rating:
See here : [https://berryberry.hatenablog.jp](https://berryberry.hatenablog.jp/entry/2022/03/07/230635)
First of all, I got a couple of files "log.txt" and "rand.py".
## Given Files
"rand.py" is a program that uses UNIX time as a seed value to obtain a pseudorandom number.
```
import random
import time
import hashlib
seed = round(time.time())
random.seed(seed, version=2)
while True:
rand = random.random()
has = hashlib.sha256(str(rand).encode()).hexdigest()
flag = f"CTF{{{has}}}"
if "7a2" in has:
with open("./flag", "w") as f:
f.write(flag)
break
else:
print(f"Bad random value: {rand}")
```
"log.txt" is a output of "rand.py".
```
Bad random value: 0.33567959567961436
Bad random value: 0.8913897703358419
Bad random value: 0.3032054069265432
Bad random value: 0.6860829464688437
Bad random value: 0.2658087107328536
Bad random value: 0.8903005048882441
Bad random value: 0.914630909612433
Bad random value: 0.9688578899818961
Bad random value: 0.7925090397955323
Bad random value: 0.10136501216336935
Bad random value: 0.568451491382639
Bad random value: 0.16898065821921437
Bad random value: 0.5541712073794856
Bad random value: 0.029926361216790154
Bad random value: 0.18218590474521223
Bad random value: 0.49713845657579536
Bad random value: 0.7631162105077507
Bad random value: 0.7386939443532723
Bad random value: 0.5815609491717452
Bad random value: 0.5905894610211082
Bad random value: 0.09018146469820387
Flag created
```
##
## Solution
We can see "flag created" in log.txt at 22 lines, so we need to calculate the UNIX time which has "7a2" in line22. I obtained by the use of brute-force.
```
import random
import time
import hashlib
now = 1646547850 # current time when i solved
tmp = [0.33567959567961436, 0.8913897703358419, 0.3032054069265432, 0.6860829464688437, 0.2658087107328536, 0.8903005048882441, 0.914630909612433, 0.9688578899818961, 0.7925090397955323, 0.10136501216336935, 0.568451491382639, 0.16898065821921437, 0.5541712073794856, 0.029926361216790154, 0.18218590474521223, 0.49713845657579536, 0.7631162105077507, 0.7386939443532723, 0.5815609491717452, 0.5905894610211082, 0.09018146469820387]
while (now > 0):
random.seed(now, version=2)
for cnt in range(21):
rand = random.random()
if (rand != tmp[cnt]):
break
else:
print(now)
exit()
now -= 1
```
Then, run "rand.py" using UNIX time which obtained earlier.
Finally, we can get FLAG.
```
CTF{82eafc43f229ea3ffe489444c973a8bbbfbbbac54095ba207a222e9918290fdc}
```