



"""simple docstring"""






import numpy as np
import qiskit






def 	snake_case_  (				A_ :		int = 8,    A_ :		int | None = None						):


       '''simple docstring'''





       _lowerCamelCase						:    Union[str, Any]         =			np.random.default_rng(seed=A_						)

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

       # Quantum Circuit to simulate BB84
       _lowerCamelCase						:    Any         =			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.
       _lowerCamelCase						:    List[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						:    Dict         =			qiskit.execute(A_,    A_,    shots=1,    seed_simulator=A_						)
       # Returns the result of measurement.
       _lowerCamelCase						:    Tuple         =			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.
       _lowerCamelCase						:    Tuple         =			''''''.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.
       _lowerCamelCase						:    int         =			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"""






from maths.prime_factors import prime_factors






def 	snake_case_  (				A_ :		int						):


       '''simple docstring'''





       if not isinstance(A_,    A_						):
              _lowerCamelCase						:    str         =			F'''Input value of [number={number}] must be an integer'''
              raise TypeError(A_						)
       if number < 1:
              raise ValueError('''Input must be a positive integer'''						)
       return -1 if len(prime_factors(A_						)						) % 2 else 1


if __name__ == "__main__":
   import doctest

   doctest.testmod()


