Question: Write a function extract _ order ( meas , m , a , n ) given a measurement meas, number of qubits m , a

Write a function extract_order(meas, m, a, n) given a measurement meas, number of qubits m, a number a that is relatively prime to n. The function return the order r if found using the successive approximation described above. If you cannot find the order, return None.
A modular_exponentiation function is given to you.
def modular_exponentiate(a, k, n): # a^k \mod n
mu = a
res =1
while k >0:
if k %2==1:
res =(res * mu)% n
mu =(mu * mu)% n
k = k //2
return res
def extract_order(meas, m, a, n):
# your code here
for r in range(1, n):
if modular_exponentiate(a, r, n)== meas:
return r
return None
r1= extract_order(75,7,5,91)
assert r1==12
r2= extract_order(53,7,5,91)
assert r2==12
r3= extract_order(96,7,5,91)
assert r3==12
r4= extract_order(32,7,5,91)
assert r4==12
r5= extract_order(64,7,5,91)
assert r5== None
r6= extract_order(11,7,5,91)
assert r6==12

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!