


"""simple docstring"""







import math

import numpy as np
import qiskit
from qiskit import Aer, ClassicalRegister, QuantumCircuit, QuantumRegister, execute




def        UpperCAmelCase__	(lowerCAmelCase_ = 3       ):




					'''simple docstring'''


					if isinstance(lowerCAmelCase_  ,						lowerCAmelCase_       ):
										raise TypeError("number of qubits must be a integer."       )
					if number_of_qubits <= 0:
										raise ValueError("number of qubits must be > 0."       )
					if math.floor(lowerCAmelCase_       ) != number_of_qubits:
										raise ValueError("number of qubits must be exact integer."       )
					if number_of_qubits > 10:
										raise ValueError("number of qubits too large to simulate(>10)."       )

					__SCREAMING_SNAKE_CASE						       =    QuantumRegister(lowerCAmelCase_  ,						"qr"       )
					__SCREAMING_SNAKE_CASE						       =    ClassicalRegister(lowerCAmelCase_  ,						"cr"       )

					__SCREAMING_SNAKE_CASE						       =    QuantumCircuit(lowerCAmelCase_  ,						lowerCAmelCase_       )

					__SCREAMING_SNAKE_CASE						       =    number_of_qubits

					for i in range(lowerCAmelCase_       ):
										quantum_circuit.h(number_of_qubits - i - 1       )
										counter -= 1
										for j in range(lowerCAmelCase_       ):
															quantum_circuit.cp(np.pi / 2 ** (counter - j)  ,						lowerCAmelCase_  ,						lowerCAmelCase_       )

					for k in range(number_of_qubits // 2       ):
										quantum_circuit.swap(lowerCAmelCase_  ,						number_of_qubits - k - 1       )

					# measure all the qubits
					quantum_circuit.measure(lowerCAmelCase_  ,						lowerCAmelCase_       )
					# simulate with 10000 shots
					__SCREAMING_SNAKE_CASE						       =    Aer.get_backend("qasm_simulator"       )
					__SCREAMING_SNAKE_CASE						       =    execute(lowerCAmelCase_  ,						lowerCAmelCase_  ,						shots=1_0000       )

					return job.result().get_counts(lowerCAmelCase_       )


if __name__ == "__main__":
		print(
		    F"Total count for quantum fourier transform state is: \
    {quantum_fourier_transform(3)}"
		)




"""simple docstring"""







a__    :							Optional[Any]            =					'''ABCDEFGHIJKLMNOPQRSTUVWXYZ'''




def        UpperCAmelCase__	():




					'''simple docstring'''


					__SCREAMING_SNAKE_CASE						       =    input("Enter message: "       )
					__SCREAMING_SNAKE_CASE						       =    input("Enter key [alphanumeric]: "       )
					__SCREAMING_SNAKE_CASE						       =    input("Encrypt/Decrypt [e/d]: "       )

					if mode.lower().startswith("e"       ):
										__SCREAMING_SNAKE_CASE						       =    "encrypt"
										__SCREAMING_SNAKE_CASE						       =    encrypt_message(lowerCAmelCase_  ,						lowerCAmelCase_       )
					elif mode.lower().startswith("d"       ):
										__SCREAMING_SNAKE_CASE						       =    "decrypt"
										__SCREAMING_SNAKE_CASE						       =    decrypt_message(lowerCAmelCase_  ,						lowerCAmelCase_       )

					print(f"""\n{mode.title()}ed message:"""       )
					print(lowerCAmelCase_       )




def        UpperCAmelCase__	(lowerCAmelCase_  ,						lowerCAmelCase_       ):




					'''simple docstring'''


					return translate_message(lowerCAmelCase_  ,						lowerCAmelCase_  ,						"encrypt"       )




def        UpperCAmelCase__	(lowerCAmelCase_  ,						lowerCAmelCase_       ):




					'''simple docstring'''


					return translate_message(lowerCAmelCase_  ,						lowerCAmelCase_  ,						"decrypt"       )




def        UpperCAmelCase__	(lowerCAmelCase_  ,						lowerCAmelCase_  ,						lowerCAmelCase_       ):




					'''simple docstring'''


					__SCREAMING_SNAKE_CASE						       =    []
					__SCREAMING_SNAKE_CASE						       =    0
					__SCREAMING_SNAKE_CASE						       =    key.upper()

					for symbol in message:
										__SCREAMING_SNAKE_CASE						       =    LETTERS.find(symbol.upper()       )
										if num != -1:
															if mode == "encrypt":
																				num += LETTERS.find(key[key_index]       )
															elif mode == "decrypt":
																				num -= LETTERS.find(key[key_index]       )

															num %= len(lowerCAmelCase_       )

															if symbol.isupper():
																				translated.append(LETTERS[num]       )
															elif symbol.islower():
																				translated.append(LETTERS[num].lower()       )

															key_index += 1
															if key_index == len(lowerCAmelCase_       ):
																				__SCREAMING_SNAKE_CASE						       =    0
										else:
															translated.append(lowerCAmelCase_       )
					return "".join(lowerCAmelCase_       )


if __name__ == "__main__":
		main()
