import random from secret import FLAG assert FLAG.startswith('n1ctf{') assert FLAG.endswith('}') SECRET = bytes.fromhex(FLAG[6:-1]) assert len(SECRET) == 16 p = 251 e = [1, 20, 113, 149, 219] y = b'' for x in range(1, p): coeff = [random.choice(e)] + list(SECRET) y += bytes([sum(c * pow(x, i, p) for i, c in enumerate(coeff)) % p]) print(f'Token: {y.hex()}')
import sys from secret import FLAG, REGISTER, TAPS assert FLAG.startswith('flag') assert len(REGISTER) == 16 assert len(TAPS) == 5 class LFSR: def __init__(self, register, taps): self.register = register self.taps = taps def next(self): new = 0 ret = self.register[0] for i in self.taps: new ^= self.register[i] self.register = self.register[1:] + [new] return ret def encrypt(): enc_flag = [] for char in FLAG.encode(): enc_char = 0 for binary in '{:08b}'.format(char): enc_char <<= 1 enc_char += (int(binary) ^ lfsr.next()) enc_flag.append(enc_char) return bytes(enc_flag)