sch9_ctf_3/tasks/cringe_random/cringe_random.py

27 lines
532 B
Python
Raw Normal View History

2023-08-25 14:51:08 +00:00
import random
n = 10
flag_len = 20
state = [random.randint(0, (1 << n) - 1) for i in range(n)]
k = 0
def update_state():
for i in range(n):
state.append(state[0])
for j in range(1, n):
state[j] ^= ((state[0] >> j) & 1) << i
state.pop(0)
def get_random():
global k
if(k == n):
k = 0
update_state()
k += 1
return state[k - 1]
flag='ctf{' + (''.join([chr(get_random() % 26 + ord('a')) for i in range(flag_len)])) + '}'
print(flag)
update_state()
print(state)