-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQuantum_Router.py
146 lines (100 loc) · 3.88 KB
/
Quantum_Router.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# -*- coding: utf-8 -*-
"""
Created on Wed Apr 22 13:32:08 2020
@author: codie
"""
from qiskit import QuantumRegister, ClassicalRegister
from qiskit import QuantumCircuit, execute, Aer
import numpy as np
#################################User_Input######################
n = int(input("Length of the password[Root]:-"))
Pass_R = list(map(float,input("Set the Password[Root](Any number between [0,3](Int) with space between each):- ").strip().split()))[:n]
Rand = 2
#Rand = int(input("Enter a random number between [1,10] for your dummey signel creation :- "))
Signal = str(input("Put your Binary signal here:-"))
################################/User_Input#####################
##############################Manual_Input#######################
'''
Rand = [2,3,4]
n = 3
Pass_R= [1,2,3]
Pass = [1,2,6]
Data = [0,1,0,0,0,0,1,1,0,1,1,0,1,1,1,1,0,1,1,0,0,1,0,0,0,1,1,0,1,0,0,1,0,1,1,0,0,1,0,1]
'''
##############################/Manual_Input#######################
############################/Algorithm##########################
def Root(Pass,Input):
m = len(Pass)
output = 0
if m >= n:
qc = QuantumCircuit()
q = QuantumRegister(3+2*m, 'q')
c = ClassicalRegister(1, 'c')
qc.add_register(q)
qc.add_register(c)
qc.u3(np.pi*Input,0,0,q[0])
qc.u3(np.pi / Rand, 0, 0, q[1])
for i in range (n):
qc.u3(np.pi-Pass_R[i], 0, 0, q[3+i])
for i in range(m):
qc.u3(Pass[i], 0, 0, q[3+i])
qc.mct(q[3:3+m], q[2], q[3+m:3+2*m])
qc.cswap(q[2], q[0], q[1])
qc.measure(q[1], c[0])
Shots = 1
backend = Aer.get_backend('qasm_simulator')
job = execute(qc, backend=backend,shots = Shots)
job_result = job.result()
output = (list(job_result.get_counts(qc).keys())[0])
#print(job_result.get_counts(qc))
if m<n:
qc = QuantumCircuit()
q = QuantumRegister(3+2*n, 'q')
c = ClassicalRegister(1, 'c')
qc.add_register(q)
qc.add_register(c)
qc.x(q[0])
qc.u3(np.pi / Rand, 0, 0, q[1])
for i in range (n):
qc.u3(np.pi-Pass_R[i], 0, 0, q[3+i])
for i in range(m):
qc.u3(Pass[i], 0, 0, q[3+i])
qc.mct(q[3:3+n], q[2], q[3+n:3+2*n])
qc.cswap(q[2], q[0], q[1])
qc.measure(q[1], c[0])
Shots = 1
backend = Aer.get_backend('qasm_simulator')
job = execute(qc, backend=backend,shots = Shots)
job_result = job.result()
output = (list(job_result.get_counts(qc).keys())[0])
#print(job_result.get_counts(qc))
return output
#########################/Algorithm##################
######################Some_helpful_Function############
def List_To_String(A):
str = ""
for i in A:
str+= i
return str
def String_To_List(A):
C = []
for i in (list(A)):
C.append(int(i))
return C
####################/Some_helpful_Function##############
###################Output#######################
Data = String_To_List(Signal)
p = 1
while p!=0:
Output = []
print("Data has been saved enter password to recover")
m1 = int(input("Length of your password:-"))
Pass = list(map(float,input("Enter your Password:- ").strip().split()))[:m1]
for i in range (len(Data)):
#print(Root(Pass,Data[i]))
#print (type(Root(Pass,Data[i])))
Output.append(Root(Pass,Data[i]))
print (List_To_String(Output))
p = int(input("Enter 1 to continue and 0 to Exit :-"))
#################/Output#######################
'''End'''