


'''simple docstring'''







import numpy as np
import qiskit


def 	SCREAMING_SNAKE_CASE_					(  _UpperCAmelCase	:	int = 8    ,_UpperCAmelCase	:	int | None = None  )  ->			str:
       _a    : int     					=np.random.default_rng(seed=_UpperCAmelCase  )

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

       # Quantum Circuit to simulate BB84
       _a    : Optional[Any]     					=qiskit.QuantumCircuit(_UpperCAmelCase    ,name="""BB84"""  )

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

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

       bbaa_circ.barrier()
       bbaa_circ.measure_all()

       # Simulate the quantum circuit.
       _a    : Dict     					=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.
       _a    : Union[str, Any]     					=qiskit.execute(_UpperCAmelCase    ,_UpperCAmelCase    ,shots=1    ,seed_simulator=_UpperCAmelCase  )
       # Returns the result of measurement.
       _a    : Optional[Any]     					=job.result().get_counts(_UpperCAmelCase  ).most_frequent()

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

       # Get final key. Pad with 0 if too short, otherwise truncate.
       _a    : List[Any]     					=gen_key[:key_len] if len(_UpperCAmelCase  ) >= key_len else gen_key.ljust(_UpperCAmelCase    ,"""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 isqrt


def 	SCREAMING_SNAKE_CASE_					(  _UpperCAmelCase	:	int  )  ->			bool:
       return all(number % divisor != 0 for divisor in range(2    ,isqrt(_UpperCAmelCase  ) + 1  )  )


def 	SCREAMING_SNAKE_CASE_					(  _UpperCAmelCase	:	int = 10**6  )  ->			int:
       _a    : List[Any]     					=0
       _a    : str     					=1
       _a    : Optional[Any]     					=7
       while prime_candidate < max_prime:
              primes_count += is_prime(_UpperCAmelCase  )

              cube_index += 1
              prime_candidate += 6 * cube_index

       return primes_count


if __name__ == "__main__":
   print(F"{solution() = }")


