Seed of Life
Noobmaster
This one was a pretty good challenge, the code for it -
import random
seed = REDACTED
assert seed in range(10000000)
random.seed(seed)
for i in range(19):
random.seed(random.random())
seedtosave = random.random()
print("share1:")
for add in range(0, 1000):
random.seed(seedtosave+add)
for i in range(0, 100):
print(random.random())
print("share2:")
for add in range(0, 1000):
random.seed(seedtosave-add)
for i in range(0, 1000):
print(random.random())
print("share3:")
random.seed(seedtosave)
for i in range(0, 100):
print(random.random()*100)
So first of all let me explain what the code is doing
import random
seed = REDACTED
assert seed in range(10000000)
random.seed(seed)
this is importing random, seed is REDACTED and the assert seed in range(10000000) means that the seed is less than 10000000 now what does seed do? for example -
import random
random.seed(10)
print(random.random())
#the generator creates a random number based on the seed value, so if the seed value is 10, you will always get 0.5714025946899135 as the first random number.
source for the above code - https://www.w3schools.com/python/trypython.asp?filename=demo_ref_random_seed
so you can see that if I do random.seed(10) you get a specific number. Also we are given an out.txt with the numbers for example - 0.5714025946899135 so with this we can find out the seed is 10 like that we need to find out the seed and that is gonna be the flag! so the out.txt is very big to show here so here is the link - https://ctf.idek.team/handouts/crypto/Seedoflife/out.txt Now, we make the solve script -
import random # imports the random module
req = [0.5327486342598738, 0.3995021462380498, 0.0719911754621515, 0.14039488932883026, 0.6294096855571742] # this are the first 5 numbers of share 1 taken from the out.txt
for i in range(10000000): # 10000000 beacuse thats the number in the challenge
print(f'Trying: {i}', end='\r') # so it will try from 0 to 10000000 and \r for the nice little animation
random.seed(i) # trys to seed number from 0 to 10000000
# now we copy the rest of the code from the challenge itself!
for i in range(19):
random.seed(random.random())
seedtosave = random.random()
# removed print("share1:")
for add in range(0, 1000):
random.seed(seedtosave+add)
# now a code to check if random.random() with the seed is = the req or not
test = [random.random() for _ in range(5)]
if test == req:
print('Found seed!')
print(i)
quit()
it will print -