-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchallenge22.py
More file actions
39 lines (37 loc) · 1.22 KB
/
challenge22.py
File metadata and controls
39 lines (37 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env python3
# Crack an MT19937 seed
import time
from utils import ans_check, Random
# --------------------------------------------------------
# ---------------------- functions -----------------------
# --------------------------------------------------------
def wait(seconds: int):
timer_rand = Random()
if type(seconds) is float:
seconds = int(seconds)
sleep_time = timer_rand.random()/(2**32)*seconds
time.sleep(sleep_time)
def find_seed(rand_output) -> int:
current_time = int(time.time())
while True:
rand_guess = Random(current_time)
rng_guess = rand_guess.random()
if rng_guess == rand_output:
return current_time
current_time -= 1
# --------------------------------------------------------
# ------------------------- main -------------------------
# --------------------------------------------------------
def main():
print('starting program')
wait(100)
seed = int(time.time())
rand = Random(seed)
rng = rand.random()
print(f'{rng = }\n{seed = }')
wait(100)
extracted_seed = find_seed(rng)
print(f'Extracted seed: {extracted_seed}')
ans_check(seed, extracted_seed)
if __name__ == "__main__":
main()