flag = open('flag.txt','rb').read().strip() random.seed(int(os.urandom(64).hex(),16)) # super secure! key = b'' x=random.randbytes(1) for i inrange(16): key += x random.seed(int(x.hex(),16)) x = random.randbytes(1) encrypted_flag = encrypt(flag, key) print("Encrypted flag (in hex):", encrypted_flag.hex())
# Encrypted flag (in hex): 04b5b9e11ee236a1c0784882d3f8efe9cc28b2993971a83413907e9833190e2a99e611c748966d61489f84ea2f331c7c
ciphertext = long_to_bytes(0x04b5b9e11ee236a1c0784882d3f8efe9cc28b2993971a83413907e9833190e2a99e611c748966d61489f84ea2f331c7c) for i inrange(0,256): key = b'' x = bytes([i]) for j inrange(16): key += x random.seed(int(x.hex(),16)) x=random.randbytes(1) try: flag = decrypt(ciphertext,key) if(b'ictf'in flag): print(flag) except: continue
#!/usr/local/bin/python import random flag = open('flag.txt').read() print("Welcome! Let's play a game!") defprint_menu(): print("""1) Get random bits 2) Guess number 3) Exit """)
whileTrue: print_menu() x = int(input("Choice: ")) if x == 1: print("How many random numbers do you want?") r = int(input()) arr = [] for i inrange(r): arr.append(random.getrandbits(32)) print(f'Here you go: {arr}') if x == 2: to_guess = random.randint(0,65535*65537) guess = int(input("Enter guess: ")) if guess == to_guess: print(f"Wow! Here's your flag: {flag}") else: print('Incorrect!') exit() if x == 3: exit()
from Crypto.Util.number import * c_list = [0xe18ea0,0xe18e9a,0xe18eab,0xe18e9d,0xe18eb2,0xe18e9a,0xe18daa,0xe18ea9,0xe18dae,0xe18da8,0xe18e9d,0xe18da8,0xe18daa,0xe18e9b,0xe18e96,0xe18da8,0xe18daa,0xe18daa,0xe18dae,0xe18e96,0xe18e9f,0xe18dab,0xe18eaf,0xe18da7,0xe18ea9,0xe18d98,0xe18eb4] s = "" for i in c_list: s+=chr(ord(long_to_bytes(i).decode())-0x1337) print(s)
defn_to_bit_list(n, nbits=256): F = GF(2) result = [Nonefor _ inrange(nbits)] for i inrange(nbits): result[i] = F((n >> (nbits - i - 1)) % 2) return result
defbit_list_to_n(bl): result = 0 for b in bl: result *= 2 result += int(b) return result
deftransition_matrix(engine, nbits=256): state = engine.state columns = [] # calculate the standard matrix for i inrange(nbits): seed = 1 << (nbits - i - 1) engine.raw_seed(seed) columns.append(n_to_bit_list(engine.next_state()))
engine.state = state return matrix(GF(2), columns).transpose()
defjump(engine, num_steps, mat=None): if mat isNone: mat = transition_matrix(engine)
state = engine.raw_state() v = vector(n_to_bit_list(state)) v2 = mat^num_steps * v newstate = bit_list_to_n(v2) engine.raw_seed(newstate)
deflua_nth_random(e, n, mat=None): # lua advances the state 16 times after setting the seed in math.randomseed jump(e, n + 16, mat) return e.next() & (2**32 - 1)
defsolve(): withopen('chall.bmp', 'rb') as f: data = f.read() header = data[:0x8a] enc = data[0x8a:] dt = datetime.strptime('31 Jan 2020, 20:38 +0000', '%d %b %Y, %H:%M %z') e = LuaXoshiro() mat = transition_matrix(e) for i inrange(60): seed = int(dt.timestamp() + i) e.seed(seed) key = str(lua_nth_random(e, 1_000_000_000_000_000)).encode() cipher = ARC4.new(key, drop=3072) dec = cipher.decrypt(enc) withopen(f'decrypted/{i:02}.bmp', 'wb') as f: f.write(header + dec)