




"""simple docstring"""






import numpy as np
import qiskit







def      _snake_case			(				lowercase__ = 8							,    lowercase__ = None		):
				_lowerCamelCase     :			str    =    np.random.default_rng(seed=lowercase__		)

				# Roughly 25% of the qubits will contribute to the key.
				# So we take more than we need.
				_lowerCamelCase     :			List[str]    =    6 * key_len
				# Measurement basis for Alice's qubits.
				_lowerCamelCase     :			int    =    rng.integers(2							,    size=lowercase__		)
				# The set of states Alice will prepare.
				_lowerCamelCase     :			str    =    rng.integers(2							,    size=lowercase__		)
				# Measurement basis for Bob's qubits.
				_lowerCamelCase     :			str    =    rng.integers(2							,    size=lowercase__		)

				# Quantum Circuit to simulate BB84
				_lowerCamelCase     :			Dict    =    qiskit.QuantumCircuit(lowercase__							,    name='BB84'		)

				# Alice prepares her qubits according to rules above.
				for index, _ in enumerate(lowercase__		):
								if alice_state[index] == 1:
												bbaa_circ.x(lowercase__		)
								if alice_basis[index] == 1:
												bbaa_circ.h(lowercase__		)
				bbaa_circ.barrier()

				# Bob measures the received qubits according to rules above.
				for index, _ in enumerate(lowercase__		):
								if bob_basis[index] == 1:
												bbaa_circ.h(lowercase__		)

				bbaa_circ.barrier()
				bbaa_circ.measure_all()

				# Simulate the quantum circuit.
				_lowerCamelCase     :			List[str]    =    qiskit.Aer.get_backend('aer_simulator'		)
				# We only need to run one shot because the key is unique.
				# Multiple shots will produce the same key.
				_lowerCamelCase     :			List[Any]    =    qiskit.execute(lowercase__							,    lowercase__							,    shots=1							,    seed_simulator=lowercase__		)
				# Returns the result of measurement.
				_lowerCamelCase     :			Optional[Any]    =    job.result().get_counts(lowercase__		).most_frequent()

				# Extracting the generated key from the simulation results.
				# Only keep measurement results where Alice and Bob chose the same basis.
				_lowerCamelCase     :			Optional[int]    =    ''.join(
				    [
				        result_bit
				        for alice_basis_bit, bob_basis_bit, result_bit in zip(
				            lowercase__							,    lowercase__							,    lowercase__		)
				        if alice_basis_bit == bob_basis_bit
				    ]		)

				# Get final key. Pad with 0 if too short, otherwise truncate.
				_lowerCamelCase     :			Union[str, Any]    =    gen_key[:key_len] if len(lowercase__		) >= key_len else gen_key.ljust(lowercase__							,    '0'		)
				return key


if __name__ == "__main__":
			print(F"The generated key is : {bbaa(8, seed=0)}")
			from doctest import testmod

			testmod()





"""simple docstring"""






lowercase__     						=						{
    """meter""": """m""",
    """kilometer""": """km""",
    """megametre""": """Mm""",
    """gigametre""": """Gm""",
    """terametre""": """Tm""",
    """petametre""": """Pm""",
    """exametre""": """Em""",
    """zettametre""": """Zm""",
    """yottametre""": """Ym""",
}
# Exponent of the factor(meter)
lowercase__     						=						{
    """m""": 0,
    """km""": 3,
    """Mm""": 6,
    """Gm""": 9,
    """Tm""": 12,
    """Pm""": 15,
    """Em""": 18,
    """Zm""": 21,
    """Ym""": 24,
}







def      _snake_case			(				lowercase__							,    lowercase__							,    lowercase__		):
				_lowerCamelCase     :			List[Any]    =    from_type.lower().strip('s'		)
				_lowerCamelCase     :			List[Any]    =    to_type.lower().strip('s'		)

				_lowerCamelCase     :			Optional[int]    =    UNIT_SYMBOL.get(lowercase__							,    lowercase__		)
				_lowerCamelCase     :			Any    =    UNIT_SYMBOL.get(lowercase__							,    lowercase__		)

				if from_sanitized not in METRIC_CONVERSION:
								_lowerCamelCase     :			Tuple    =    (
								    f'''Invalid \'from_type\' value: {from_type!r}.\n'''
								    f'''Conversion abbreviations are: {', '.join(lowercase__		)}'''
								)
								raise ValueError(lowercase__		)
				if to_sanitized not in METRIC_CONVERSION:
								_lowerCamelCase     :			Any    =    (
								    f'''Invalid \'to_type\' value: {to_type!r}.\n'''
								    f'''Conversion abbreviations are: {', '.join(lowercase__		)}'''
								)
								raise ValueError(lowercase__		)
				_lowerCamelCase     :			List[Any]    =    METRIC_CONVERSION[from_sanitized]
				_lowerCamelCase     :			int    =    METRIC_CONVERSION[to_sanitized]
				_lowerCamelCase     :			List[str]    =    1

				if from_exponent > to_exponent:
								_lowerCamelCase     :			List[str]    =    from_exponent - to_exponent
				else:
								_lowerCamelCase     :			List[Any]    =    -(to_exponent - from_exponent)

				return value * pow(10							,    lowercase__		)


if __name__ == "__main__":
			from doctest import testmod

			testmod()