



'''simple docstring'''





import numpy as np
import qiskit
def    _SCREAMING_SNAKE_CASE  (       UpperCamelCase = 8							,    UpperCamelCase = None			):



    """simple docstring"""





    lowerCAmelCase__ :  Union[str, Any]							      =					np.random.default_rng(seed=UpperCamelCase			)

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

    # Quantum Circuit to simulate BB84
    lowerCAmelCase__ :  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.
    lowerCAmelCase__ :  Any							      =					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__ :  Optional[int]							      =					qiskit.execute(UpperCamelCase							,    UpperCamelCase							,    shots=1							,    seed_simulator=UpperCamelCase			)
    # Returns the result of measurement.
    lowerCAmelCase__ :  Union[str, 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.
    lowerCAmelCase__ :  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.
    lowerCAmelCase__ :  Tuple							      =					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()








from math import sqrt

def 					UpperCAmelCase_							(      __UpperCAmelCase						:	int							)					-> bool:

      if 1 < number < 4:
            # 2 and 3 are primes
            return True
      elif number < 2 or number % 2 == 0 or number % 3 == 0:
            # Negatives, 0, 1, all even numbers, all multiples of 3 are not primes
            return False

      # All primes number are in format of 6k +/- 1
      for i in range(5			,			int(sqrt(__UpperCAmelCase							) + 1							)			,			6							):
            if number % i == 0 or number % (i + 2) == 0:
                  return False
      return True

def 					UpperCAmelCase_							(      __UpperCAmelCase						:	int = 1_00_01							)					-> int:
      SCREAMING_SNAKE_CASE_							=			0
      SCREAMING_SNAKE_CASE_							=			1
      while count != nth and number < 3:
            number += 1
            if is_prime(__UpperCAmelCase							):
                  count += 1
      while count != nth:
            number += 2
            if is_prime(__UpperCAmelCase							):
                  count += 1
      return number


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