Tags: python quantum crypto 

Rating: 4.5

#!/usr/bin/env python2
import math

from pwn import *

"""
Read this: https://inst.eecs.berkeley.edu/~cs191/fa07/lectures/lecture22_fa07.pdf

I don't really know much about quantum computers.
Credit goes to [bobert](https://github.com/rstrand2357) for figuring out how to solve this.
I took a page of notes during a phone call with him.
I bit twiddle much better than he does.

I also put some fmt.Println debug statements in the provided go code

The challenge creates a list of possible bombs. You have to tell the program
which bombs will explode and which won't, but if you actively observe an
active bomb, it'll explode.

Apparently there is some quantum magic where if you have a chain of
Hadamard - phase shift - Hadamard - possible bomb[n]
blocks, you can figure out if they are active bombs or not if you
do enough of these with a small enough phase shift each time.

We do a total of 2000 (bignum) sets of those four blocks.
Each phase shift is pi/bignum radians

So, for each bomb n:
send (2000*4) for the number of gates
send a Hadamard gate
send a phase shift by pi/2000
send a Hadamard gate
send the index of the possible bomb n
get the return value (0:safe, 1:bomb)

Repeat for all 112 bombs

Send back the list of bombs / not-bombs
"""

context.endian = "big"
context.log_level = "INFO"

# How many Hadamard-phase-Hadamard-bomb blocks
bignum = 2000

# Gate types numbers are 0x70 + the gate index
hadamard = p8(0x70 + 4)
# Phase rotation is a 64-bit float
phase_rot = p8(0x70 + 6) + struct.pack("

Original writeup (https://gist.github.com/duckythescientist/f46036b1b13c9e5751eae9026c04c444).