summaryrefslogtreecommitdiffstats
path: root/solve/main.py
blob: 67a5a91d87e2cfa6961cefc63c5efda441a4d153 (plain) (blame)
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
import os
import struct

BITS = 56

FLAG = os.getenv("FLAG", "CSCG{TESTFLAG}")

A = int.from_bytes(os.urandom(BITS//8), "little")
B = int.from_bytes(os.urandom(BITS//8), "little")
SEED = int.from_bytes(os.urandom(BITS//8), "little")

def rng(x, size):
    return (x*A+B) & ((2**size)-1)

def gen_random(seed, bits, mask):
    state = seed
    while True:
        state = rng(state, bits)
        yield state & mask

def main():
    print("Here are some random numbers, now guess the flag")
    rng = gen_random(SEED, BITS, 0xFF)
    for i in range(len(FLAG)):
        print(next(rng) ^ ord(FLAG[i]))

if __name__ == "__main__":
    main()