


import numpy as np
import qiskit







def     _lowercase							(  __lowerCamelCase      :       Tuple = 8		,__lowerCamelCase      :       List[str] = None      )	-> str:





     '''simple docstring'''





     UpperCamelCase__				:	Tuple										=  np.random.default_rng(seed=_lowerCAmelCase      )

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

     # Quantum Circuit to simulate BB84
     UpperCamelCase__				:	List[Any]										=  qiskit.QuantumCircuit(_lowerCAmelCase		,name='''BB84'''      )

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

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

     bbaa_circ.barrier()
     bbaa_circ.measure_all()

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

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

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


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

   testmod()











from typing import TYPE_CHECKING

from ...utils import _LazyModule


__lowerCamelCase			:	str					    =	{"""tokenization_byt5""": ["""ByT5Tokenizer"""]}


if TYPE_CHECKING:
    from .tokenization_byta import ByTaTokenizer
else:
    import sys

    __lowerCamelCase			:	List[str]					    =	_LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)
