Snake Charmer undo three chained Python transforms in reverse

rev
flag L3m0n{2242060639c0e971ff0ffe2ad1917ff5}

A 75-point lesson: a short Python checker hides the password behind three chained transforms. Nothing cryptographic - just run the steps backwards, in reverse order.

The checker, charm(), does this to the input: reverse the string, add 3 to every character code, then XOR each code with 0x21, and compare the resulting list against a hard-coded SECRET array.

Insight

Undoing a chain of transforms means undoing the last step first. XOR is its own inverse (x ^ k ^ k == x), so step 3 undoes trivially; step 2 just needs the matching subtraction; and step 1's reversal needs to be applied last, since it was applied first going forward.

python
1SECRET = [161, 25, 72, 72, 27, 21, 29, 21, 70, 69, 20, 73, 72, 72, 18, 72, 72,
2          21, 27, 29, 73, 18, 71, 29, 23, 24, 18, 24, 18, 20, 22, 20, 20, 95,
3          80, 18, 81, 23, 110]
4
5undo3 = [n ^ 0x21 for n in SECRET]              # undo the XOR
6undo2 = [n - 3 for n in undo3]                  # undo the +3
7flag  = "".join(chr(n) for n in undo2)[::-1]    # undo the reverse, last
8print(flag)
output
L3m0n{2242060639c0e971ff0ffe2ad1917ff5}

Note

The lesson's solver skeleton ships with the XOR line already filled in and two ??? blanks to fill - they're exactly the 3 and the [::-1]. The one thing worth keeping straight while filling them in: the order of operations reverses, not just each individual step.