Hacky Holidays: Quantum Snacks Writeup

Contents
Updated on 2021-12-10

I recently participated in the Hacky Holidays CTF and came across a very interesting challenge that revolved around quantum computing, we are given qbits and 3 logic gates, qbits in this scenario are represented as vectors, we are also provided with the a formula to calculate the change in the state of a qbit upon interaction with a qbit, more detailed information can be found below,

This is relatively simple, using the logic gates and the given qbit we can calculate that there are 8 possible states.

This is where the challenge gets interesting, to solve this question I had to begin representing the problem programmatically, I had chosen python to do so.

Above I defined the logic gates provided and the square root number, the code assumes the qbits to be vectors and gates to be matrices. I have also defined two functions, one to multiply vectors with matrices and the other that compares a starting and ending state, it randomly passes the qbit through a gate until both the states are the same.

using the defined functions we multiply the vectors with a randomly picked gate until we get our desired output, as shown below,

Using our programmatic implementation this was easy to implement as we now have access to all gates and can obtain our result by setting a condition for the output.

In the code since we cannot directly find out the smallest number of gates possible we must manually increase the number of gates we set as the minimum in the condition.

I found this CTF very cool and interesting, personally its not something I’ve seen very frequently. The entire program I used to solve the challenge can be found here

I hope you found the challenge as interesting as I did!