cscg24-cry3

CSCG 2024 Challenge 'Intro Crypto 3'
git clone https://git.sinitax.com/sinitax/cscg24-cry3
Log | Files | Refs | sfeed.txt

main.py (638B)


      1import os
      2import struct
      3
      4BITS = 56
      5
      6FLAG = os.getenv("FLAG", "CSCG{TESTFLAG}")
      7
      8A = int.from_bytes(os.urandom(BITS//8), "little")
      9B = int.from_bytes(os.urandom(BITS//8), "little")
     10SEED = int.from_bytes(os.urandom(BITS//8), "little")
     11
     12def rng(x, size):
     13    return (x*A+B) & ((2**size)-1)
     14
     15def gen_random(seed, bits, mask):
     16    state = seed
     17    while True:
     18        state = rng(state, bits)
     19        yield state & mask
     20
     21def main():
     22    print("Here are some random numbers, now guess the flag")
     23    rng = gen_random(SEED, BITS, 0xFF)
     24    for i in range(len(FLAG)):
     25        print(next(rng) ^ ord(FLAG[i]))
     26
     27if __name__ == "__main__":
     28    main()