


import numpy as np
import qiskit




def      UpperCAmelCase__ (lowerCAmelCase_ = 8						,		lowerCAmelCase_ = None     ):




					'''simple docstring'''


					__SCREAMING_SNAKE_CASE		     =       np.random.default_rng(seed=SCREAMING_SNAKE_CASE_     )

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

					# Quantum Circuit to simulate BB84
					__SCREAMING_SNAKE_CASE		     =       qiskit.QuantumCircuit(SCREAMING_SNAKE_CASE_						,		name="BB84"     )

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

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

					bbaa_circ.barrier()
					bbaa_circ.measure_all()

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

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

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


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

		testmod()




"""simple docstring"""







from math import asin, atan, cos, radians, sin, sqrt, tan

a__       :							List[str]        =  6_37_81_37.0
a__       :							Tuple        =  6_35_67_52.31_42_45
a__       :							str        =  6_3_7_8_1_3_7




def      UpperCAmelCase__ (lowerCAmelCase_						,		lowerCAmelCase_						,		lowerCAmelCase_						,		lowerCAmelCase_     ):




					'''simple docstring'''


					__SCREAMING_SNAKE_CASE		     =       (AXIS_A - AXIS_B) / AXIS_A
					__SCREAMING_SNAKE_CASE		     =       atan((1 - flattening) * tan(radians(lowerCAmelCase_     )     )     )
					__SCREAMING_SNAKE_CASE		     =       atan((1 - flattening) * tan(radians(lowerCAmelCase_     )     )     )
					__SCREAMING_SNAKE_CASE		     =       radians(lowerCAmelCase_     )
					__SCREAMING_SNAKE_CASE		     =       radians(lowerCAmelCase_     )
					# Equation
					__SCREAMING_SNAKE_CASE		     =       sin((phi_a - phi_a) / 2     )
					__SCREAMING_SNAKE_CASE		     =       sin((lambda_a - lambda_a) / 2     )
					# Square both values
					sin_sq_phi *= sin_sq_phi
					sin_sq_lambda *= sin_sq_lambda
					__SCREAMING_SNAKE_CASE		     =       sqrt(sin_sq_phi + (cos(lowerCAmelCase_     ) * cos(lowerCAmelCase_     ) * sin_sq_lambda)     )
					return 2 * RADIUS * asin(lowerCAmelCase_     )


if __name__ == "__main__":
		import doctest

		doctest.testmod()
