This is my solution to the McAfee ATR Hax 2021 cryptography challenge Light Switch Crypto. You are provided with a couple of logic statements, an encrypted message, a key, and a partially complete Python script. The challenge is to introduce the logic statements to the python code. This will allow you to run the code and retrieve the flag.
I began this challenge by noting that the output of Circuit 1 is boolean A OR B. I called this result C.
The output of Circuit 2 is boolean A NAND B. I called this result D.
The output of Circuit 3 is then C AND D. I called this output E.
Working this into the provided Python program, you can code this as:
def magic_func(A, B): C = A | B D = not(A & B) E = int(C & D) o = E return o
Running this program will return the flag, which suggests there might be a cleaner solution….
Let’s create a logic table, showing what E is for given values of A and B:
(A OR B)
(A NAND B)
|E (C AND D)|
Comparing output E with the original inputs A and B, we see that it is an XOR function, as the flag suggested. We can therefore clean up the code as follows, obtaining the same result:
def magic_func(A, B): o = int(A ^ B) return o