#!/usr/bin/env python3
# rawaq challenge #13 — multi-check crackme. pass ALL checks to reveal you have the flag.
import sys

TARGET = [82, 88, 83, 126, 103, 119, 103, 106, 115, 118, 111, 106, 121, 130, 122, 131, 121, 112, 117, 123, 121, 120, 129, 118, 141, 140, 142, 124, 144, 133, 155]
EXPECTED_LEN = 31

def check(s):
    b = s.encode()
    # check 1: length
    if len(b) != EXPECTED_LEN:
        return False
    # check 2: format anchors
    if not (s.startswith("RWQ{") and s.endswith("}")):
        return False
    # check 3: transformed bytes match table  (b[i] + i) & 0xff == TARGET[i]
    for i in range(len(b)):
        if ((b[i] + i) & 0xff) != TARGET[i]:
            return False
    return True

if __name__ == "__main__":
    g = sys.argv[1] if len(sys.argv) > 1 else input("flag> ")
    print("ACCESS GRANTED" if check(g) else "ACCESS DENIED")
