fix(q-solved): add table of contents and typo fixes

Signed-off-by: Julien CLEMENT <julien.clement@epita.fr>
This commit is contained in:
Julien CLEMENT 2022-03-26 11:32:54 +01:00
parent 355dede8e1
commit d4b4d1df2e

View File

@ -3,22 +3,27 @@ title: "Reversing quantum algorithms ~~for ctf points~~ | q-solved - zer0pts 202
date: "2022-03-25 18:00:00"
author: "Juju"
tags: ["Reverse", "Quantum", "Writeup", "zer0pts"]
toc: true
---
# Challenge description
# Intro
## Challenge description
`quantum` `reverse` | `304 pts` `8 solves`
```
I copied the solver of a reversing task from the future. But it doesn't
show the flag forever :thinking:
```
# Given files
## Given files
{{< code file="/static/q-solved/solve.py" language="py" >}}
[circuit.json](/q-solved/circuit.json)
# TL;DR
# Writeup
## TL;DR
The scripts builds a quantum circuit describing an unstructured search
algorithm inspired by the grover's algorithm. Its goal is to find among all
@ -38,17 +43,17 @@ described by the oracle.
All that remains to do for us is to understand what that criteria is.
# Reversing the Oracle
## Reversing the Oracle
We can see that the oracle is built using the `circuit.json`.
The oracle is composed of 1408 multi-controlled X (MCX) gates, each controlled by 1
or 3 input qubits with with a control state given in the json. Each MCX gate
or 3 input qubits with a control state given in the json. Each MCX gate
acts on a dedicated ancilla qubit.
After all 1408 MCX, the circuit adds an other MCX on the target qubit with all
control states set to 0. The target qubit is therefore introduced a phase shift
when all ancillas are in `|0>`.
After all 1408 MCX, the circuit adds an other MCX on the target qubit
controlled by all ancillas with all control states set to 0. The target qubit
is therefore introduced a phase shift when all ancillas are in `|0>`.
So we want all ancillas to be `|0>` but it is also their original state. We
therfore have to influence the control qubits of each MCX so that none actually
@ -66,7 +71,7 @@ the gate. Similarly, a qubit marked `True` must take value `|1>`.
So we said earlier that the MCX have either 3 or 1 control bits and that at
least 1 of the control qubits must mismatch from their control state.
# POC with trivial qubits
## POC with trivial qubits
Obviously this results in an equation system but let's see what we get with
only the obvious qubits: the ones controlling an ancilla by themselves.
@ -82,23 +87,23 @@ So let's try to set all obvious qubits:
Well, most of them are 0, except, the first byte: `z`
Which is a really good sign that we are indead decoding a flag of the form
Which is a good sign that we are indeed decoding a flag of the form
`zer0pts{...}`
# Equation system
## Equation system
For MCX with 3 control bits, we simply need to put them in an equation system,
with the trivial qubits.
For MCX with 3 control qubits, we simply need to put them in an equation
system alongside the trivial qubits.
We will have a total of 1408 equations, 1 for each MCX, each equation basically
saying that at least 1 Qubit must be different from its control state, and
saying that at least 1 qubit must be different from its control state, and
therefore equal to its assigned boolean in the json.
Once the system is solved, we will know the state of all qubits that match the
oracle, which is the one outputed by the quantum circuit. We will then be able
to decode it to get the flag.
# Solve
## Solve
I used z3 to build and solve the equation system: