




'''simple docstring'''






import random
import sys

from . import cryptomath_module as cryptomath

_lowerCAmelCase				     = (
    R''' !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`'''
    R'''abcdefghijklmnopqrstuvwxyz{|}~'''
)

def       __lowerCAmelCase (   snake_case__ ,				snake_case__ ,				snake_case__						):
			if mode == "encrypt":
						if key_a == 1:
									sys.exit(
									    "The affine cipher becomes weak when key "
									    "A is set to 1. Choose different key"						)
						if key_b == 0:
									sys.exit(
									    "The affine cipher becomes weak when key "
									    "B is set to 0. Choose different key"						)
			if key_a < 0 or key_b < 0 or key_b > len(snake_case__						) - 1:
						sys.exit(
						    "Key A must be greater than 0 and key B must "
						    F"be between 0 and {len(snake_case__						) - 1}."						)
			if cryptomath.gcd(snake_case__ ,				len(snake_case__						)						) != 1:
						sys.exit(
						    F"Key A {key_a} and the symbol set size {len(snake_case__						)} "
						    "are not relatively prime. Choose a different key."						)

def       __lowerCAmelCase (   snake_case__ ,				snake_case__						):
			__UpperCamelCase				:      Union[str, Any]									=       divmod(snake_case__ ,				len(snake_case__						)						)
			check_keys(snake_case__ ,				snake_case__ ,				"encrypt"						)
			__UpperCamelCase				:      Dict									=       ""
			for symbol in message:
						if symbol in SYMBOLS:
									__UpperCamelCase				:      Tuple									=       SYMBOLS.find(snake_case__						)
									cipher_text += SYMBOLS[(sym_index * key_a + key_b) % len(snake_case__						)]
						else:
									cipher_text += symbol
			return cipher_text

def       __lowerCAmelCase (   snake_case__ ,				snake_case__						):
			__UpperCamelCase				:      Union[str, Any]									=       divmod(snake_case__ ,				len(snake_case__						)						)
			check_keys(snake_case__ ,				snake_case__ ,				"decrypt"						)
			__UpperCamelCase				:      List[str]									=       ""
			__UpperCamelCase				:      Tuple									=       cryptomath.find_mod_inverse(snake_case__ ,				len(snake_case__						)						)
			for symbol in message:
						if symbol in SYMBOLS:
									__UpperCamelCase				:      Any									=       SYMBOLS.find(snake_case__						)
									plain_text += SYMBOLS[
									    (sym_index - key_b) * mod_inverse_of_key_a % len(snake_case__						)
									]
						else:
									plain_text += symbol
			return plain_text

def       __lowerCAmelCase (   ):
			while True:
						__UpperCamelCase				:      str									=       random.randint(2 ,				len(snake_case__						)						)
						__UpperCamelCase				:      Any									=       random.randint(2 ,				len(snake_case__						)						)
						if cryptomath.gcd(snake_case__ ,				len(snake_case__						)						) == 1 and key_b % len(snake_case__						) != 0:
									return key_b * len(snake_case__						) + key_b

def       __lowerCAmelCase (   ):
			__UpperCamelCase				:      List[str]									=       input("Enter message: "						).strip()
			__UpperCamelCase				:      Union[str, Any]									=       int(input("Enter key [2000 - 9000]: "						).strip()						)
			__UpperCamelCase				:      Tuple									=       input("Encrypt/Decrypt [E/D]: "						).strip().lower()

			if mode.startswith("e"						):
						__UpperCamelCase				:      str									=       "encrypt"
						__UpperCamelCase				:      Tuple									=       encrypt_message(snake_case__ ,				snake_case__						)
			elif mode.startswith("d"						):
						__UpperCamelCase				:      str									=       "decrypt"
						__UpperCamelCase				:      Dict									=       decrypt_message(snake_case__ ,				snake_case__						)
			print(F"\n{mode.title()}ed text: \n{translated}"						)


if __name__ == "__main__":
				import doctest

				doctest.testmod()
				# main()








'''simple docstring'''






import math

import qiskit
from qiskit import Aer, ClassicalRegister, QuantumCircuit, QuantumRegister, execute

def       __lowerCAmelCase (   snake_case__ = 1 ,				snake_case__ = 1						):
			if isinstance(snake_case__ ,				snake_case__						) or isinstance(snake_case__ ,				snake_case__						):
						raise TypeError("inputs must be integers."						)
			if (bit_a < 0) or (bit_a < 0):
						raise ValueError("inputs must be positive."						)
			if (math.floor(snake_case__						) != bit_a) or (math.floor(snake_case__						) != bit_a):
						raise ValueError("inputs must be exact integers."						)
			if (bit_a > 1) or (bit_a > 1):
						raise ValueError("inputs must be less or equal to 1."						)

			# build registers
			__UpperCamelCase				:      Tuple									=       QuantumRegister(2 ,				"qr"						)
			__UpperCamelCase				:      Dict									=       ClassicalRegister(2 ,				"cr"						)

			__UpperCamelCase				:      str									=       QuantumCircuit(snake_case__ ,				snake_case__						)

			# entanglement the qubits
			quantum_circuit.h(1						)
			quantum_circuit.cx(1 ,				0						)

			# send the information
			__UpperCamelCase				:      Optional[Any]									=       str(snake_case__						) + str(snake_case__						)

			if c_information == "11":
						quantum_circuit.x(1						)
						quantum_circuit.z(1						)
			elif c_information == "10":
						quantum_circuit.z(1						)
			elif c_information == "01":
						quantum_circuit.x(1						)
			else:
						quantum_circuit.i(1						)

			# unentangled the circuit
			quantum_circuit.cx(1 ,				0						)
			quantum_circuit.h(1						)

			# measure the circuit
			quantum_circuit.measure(snake_case__ ,				snake_case__						)

			__UpperCamelCase				:      Dict									=       Aer.get_backend("aer_simulator"						)
			__UpperCamelCase				:      Tuple									=       execute(snake_case__ ,				snake_case__ ,				shots=1_000						)

			return job.result().get_counts(snake_case__						)


if __name__ == "__main__":
				print(f'Counts for classical state send: {superdense_coding(1,1)}')



