


import numpy as np
import qiskit






def 					UpperCamelCase   (      __magic_name__	:				int = 8       ,       __magic_name__	:				int | None = None	)  ->    str:
		"""simple docstring"""




		lowercase__	     =						np.random.default_rng(seed=__magic_name__	)

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

		# Quantum Circuit to simulate BB84
		lowercase__	     =						qiskit.QuantumCircuit(__magic_name__       ,       name="""BB84"""	)

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

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

		bbaa_circ.barrier()
		bbaa_circ.measure_all()

		# Simulate the quantum circuit.
		lowercase__	     =						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.
		lowercase__	     =						qiskit.execute(__magic_name__       ,       __magic_name__       ,       shots=1       ,       seed_simulator=__magic_name__	)
		# Returns the result of measurement.
		lowercase__	     =						job.result().get_counts(__magic_name__	).most_frequent()

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

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


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

	testmod()





from math import log

from scipy.constants import Boltzmann, physical_constants

A			:						Any        =  3_0_0  # TEMPERATURE (unit = K)






def 					UpperCamelCase   (      __magic_name__	:				float       ,       __magic_name__	:				float       ,       __magic_name__	:				float       ,       )  ->    float:
		"""simple docstring"""




		if donor_conc <= 0:
				raise ValueError("""Donor concentration should be positive"""	)
		elif acceptor_conc <= 0:
				raise ValueError("""Acceptor concentration should be positive"""	)
		elif intrinsic_conc <= 0:
				raise ValueError("""Intrinsic concentration should be positive"""	)
		elif donor_conc <= intrinsic_conc:
				raise ValueError(
				    """Donor concentration should be greater than intrinsic concentration"""	)
		elif acceptor_conc <= intrinsic_conc:
				raise ValueError(
				    """Acceptor concentration should be greater than intrinsic concentration"""	)
		else:
				return (
				    Boltzmann
				    * T
				    * log((donor_conc * acceptor_conc) / intrinsic_conc**2	)
				    / physical_constants["electron volt"][0]
				)


if __name__ == "__main__":
	import doctest

	doctest.testmod()

