#!/usr/bin/env python3
"""Prize-ticket checker for the Gearloft Arcade (a fictional arcade). CougarCTF practice file.

Run it with:  python checker.py
"""

TARGET = [
    106, 101, 98, 114, 94, 86, 89, 71, 74, 94, 82, 77,
    80, 139, 97, 83, 80, 86, 144, 104, 93, 89, 148, 89,
    97, 93, 92, 101, 96, 112, 122,
]


def scramble(text):
    out = []
    for i, ch in enumerate(text):
        out.append((ord(ch) ^ 0x21) + i)
    return out


def main():
    guess = input("Ticket code: ").strip()
    if scramble(guess) == TARGET:
        print("Prize unlocked! That ticket code is the practice flag.")
    else:
        print("Nope. Read scramble() and work backwards from TARGET.")


if __name__ == "__main__":
    main()
