-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathgenerate.py
60 lines (42 loc) · 1.19 KB
/
generate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# zip -r dice.zip challenge.qasm stabilizer.py solve.py
from qiskit import QuantumCircuit
from qiskit.quantum_info import Clifford
import random
import copy
import time
from Crypto.Util.number import long_to_bytes, bytes_to_long
###########################################################
n = 400
with open("flag.txt", "rb") as f:
flag = f.read()
print(len(flag) * 8)
flag = bytes_to_long(flag)
flag_bits = f"{flag:0{n}b}"
flag_bits = flag_bits[::-1]
assert len(flag_bits) <= n
m = 10000
qc = QuantumCircuit(n)
for gate_num in range(m):
if random.randint(0,1):
f = random.choice([qc.h, qc.x, qc.y, qc.z, qc.s, qc.sdg])
i = random.choice(range(n))
f(i)
else:
f = qc.cx
i = random.sample(range(n), 2)
f(*i)
qc2 = qc.inverse()
for i in range(n):
if flag_bits[i] == "1":
print(i)
qc2.x(i)
start_time = time.time()
cliff = Clifford(qc2)
qc2_obf = cliff.to_circuit()
end_time = time.time()
print("time = {:.01f} s".format(end_time - start_time))
qc_final = qc.compose(qc2_obf)
###########################################################
s = qc_final.qasm()
with open("challenge.qasm", "w") as f:
f.write(s)