#!/usr/bin/env python2import 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 programwhich 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 ofHadamard - phase shift - Hadamard - possible bomb[n]blocks, you can figure out if they are active bombs or not if youdo 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 gatessend a Hadamard gatesend a phase shift by pi/2000send a Hadamard gatesend the index of the possible bomb nget 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 blocksbignum = 2000
# Gate types numbers are 0x70 + the gate indexhadamard = p8(0x70 + 4)# Phase rotation is a 64-bit floatphase_rot = p8(0x70 + 6) + struct.pack("