#!/usr/bin/env python3
# RAWAQ — reverse (hard). Three stages stand between you and the flag:
#   (1) a byte substitution box, (2) a fixed position permutation,
#   (3) a xorshift32 keystream. Peel them in the right order.
S = [96, 47, 202, 124, 93, 132, 222, 173, 61, 70, 99, 22, 4, 51, 104, 43, 87, 219, 208, 250, 8, 233, 212, 186, 114, 111, 191, 151, 11, 3, 0, 38, 239, 216, 102, 13, 45, 42, 71, 242, 164, 209, 203, 148, 137, 98, 57, 154, 175, 29, 179, 91, 220, 112, 68, 228, 165, 78, 117, 200, 231, 171, 80, 182, 15, 167, 184, 198, 163, 211, 120, 143, 135, 62, 9, 33, 53, 41, 36, 253, 89, 185, 25, 119, 129, 115, 247, 236, 21, 66, 190, 106, 205, 40, 27, 153, 67, 152, 217, 206, 189, 248, 214, 14, 28, 207, 156, 100, 131, 63, 210, 116, 31, 82, 227, 138, 158, 19, 44, 95, 30, 223, 144, 101, 88, 150, 23, 55, 215, 130, 255, 177, 229, 169, 232, 76, 26, 149, 176, 109, 64, 73, 121, 224, 245, 237, 94, 125, 192, 180, 74, 52, 103, 1, 83, 181, 133, 20, 193, 170, 161, 195, 107, 199, 113, 183, 24, 17, 6, 145, 48, 46, 235, 188, 126, 201, 5, 72, 141, 58, 65, 39, 84, 251, 34, 85, 86, 12, 110, 254, 139, 249, 92, 225, 127, 172, 32, 69, 204, 155, 118, 97, 221, 168, 160, 77, 10, 241, 2, 81, 128, 146, 134, 105, 60, 122, 18, 16, 166, 187, 142, 59, 178, 50, 136, 240, 157, 194, 123, 108, 56, 49, 90, 159, 162, 147, 213, 246, 218, 238, 230, 54, 197, 226, 234, 75, 79, 37, 7, 196, 252, 174, 35, 244, 140, 243]
P = [9, 30, 14, 11, 18, 3, 2, 29, 26, 15, 17, 4, 24, 0, 22, 27, 12, 28, 5, 19, 16, 1, 21, 7, 6, 32, 31, 25, 10, 20, 23, 8, 13]
K = 439041101
TG = bytes.fromhex("82e4505273c454573f042cf4ccb3259e58637dfc6e561066daea9a8d3e515d4cbd")

def _ks(s):
    while True:
        s ^= (s << 13) & 0xFFFFFFFF; s ^= s >> 17; s ^= (s << 5) & 0xFFFFFFFF
        yield s & 0xFF

def check(flag: str) -> bool:
    b = flag.encode()
    if len(b) != len(P): return False
    a = bytes(S[x] for x in b)
    c = bytes(a[P[i]] for i in range(len(P)))
    g = _ks(K)
    return bytes(x ^ next(g) for x in c) == TG

if __name__ == "__main__":
    import sys
    x = sys.argv[1] if len(sys.argv) > 1 else input("flag> ")
    print("UNLOCKED" if check(x) else "LOCKED")
