






'''simple docstring'''






import numpy as np
import qiskit




def        _SCREAMING_SNAKE_CASE  (				A  :       int = 8  ,		A  :       int | None = None  )    -> str:







   """simple docstring"""
   __snake_case				:      str     							= np.random.default_rng(seed=A  )

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

   # Quantum Circuit to simulate BB84
   __snake_case				:      List[str]     							= qiskit.QuantumCircuit(A  ,		name='BB84'  )

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

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

   bbaa_circ.barrier()
   bbaa_circ.measure_all()

   # Simulate the quantum circuit.
   __snake_case				:      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.
   __snake_case				:      List[Any]     							= qiskit.execute(A  ,		A  ,		shots=1  ,		seed_simulator=A  )
   # Returns the result of measurement.
   __snake_case				:      List[Any]     							= job.result().get_counts(A  ).most_frequent()

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

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


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

      testmod()







'''simple docstring'''






import math




class a_    :







   def __init__(self					,   __a=0)			->      Any:  # a graph with Node 0,1,...,N-1
      """simple docstring"""






      __snake_case				:      List[str]     							= n
      __snake_case				:      Tuple     							= [
          [math.inf for j in range(0					,   __a)] for i in range(0					,   __a)
      ]  # adjacency matrix for weight
      __snake_case				:      Union[str, Any]     							= [
          [math.inf for j in range(0					,   __a)] for i in range(0					,   __a)
      ]  # dp[i][j] stores minimum distance from i to j







   def     SCREAMING_SNAKE_CASE__					(self					,   __a					,   __a					,   __a)			->      Tuple:
      """simple docstring"""






      __snake_case				:      Union[str, Any]     							= w







   def     SCREAMING_SNAKE_CASE__					(self)			->      Tuple:
      """simple docstring"""






      for k in range(0					,   self.n):
         for i in range(0					,   self.n):
            for j in range(0					,   self.n):
               __snake_case				:      List[Any]     							= min(self.dp[i][j]					,   self.dp[i][k] + self.dp[k][j])







   def     SCREAMING_SNAKE_CASE__					(self					,   __a					,   __a)			->      Optional[int]:
      """simple docstring"""






      return self.dp[u][v]


if __name__ == "__main__":
      __A    	=   Graph(5)
      graph.add_edge(0, 2, 9)
      graph.add_edge(0, 4, 1_0)
      graph.add_edge(1, 3, 5)
      graph.add_edge(2, 3, 7)
      graph.add_edge(3, 0, 1_0)
      graph.add_edge(3, 1, 2)
      graph.add_edge(3, 2, 1)
      graph.add_edge(3, 4, 6)
      graph.add_edge(4, 1, 3)
      graph.add_edge(4, 2, 4)
      graph.add_edge(4, 3, 9)
      graph.floyd_warshall()
      graph.show_min(1, 4)
      graph.show_min(0, 3)