-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathme_brg.py
39 lines (31 loc) · 1.07 KB
/
me_brg.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
from qiskit import Aer
from shor.mosca_ekert.mosca_ekert import DiscreteLogMoscaEkertSharedRegister
simulator = Aer.get_backend('aer_simulator')
def get_order(g, p):
for x in range(1, p):
if g**x % p == 1:
return x
failed_attempts = list()
lowest_attempt_prob = 100
lowest_attempt_vals = None
p = 17
for g in range(2, p):
# find period r
r = get_order(g, p)
if r >= 0:
for m in range(0, r):
b = g**m % p
print("g=%d, r=%d, b=%d, exp_m=%d" % (g, r, b, m))
me_algo = DiscreteLogMoscaEkertSharedRegister(b, g, p, full_run=True, quantum_instance=simulator)
res = me_algo.run()
if res["success_prob"] == 0.00:
failed_attempts.append((g, r, b, m, res))
else:
if res["success_prob"] < lowest_attempt_prob:
lowest_attempt_vals = (g, r, b, m)
lowest_attempt_prob = res["success_prob"]
print("Failed attempts: ")
print(failed_attempts)
print("Lowest prob: ")
print(lowest_attempt_prob)
print(lowest_attempt_vals)