





'''simple docstring'''




import numpy as np
import qiskit






def        _lowerCAmelCase			(  __snake_case  : int = 8 ,							__snake_case  : 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 __future__ import annotations

from typing import TypedDict







class A__       (						UpperCAmelCase__      ):
      __UpperCamelCase       :  str
      __UpperCamelCase       :  int


def 	SCREAMING_SNAKE_CASE_					(  _UpperCAmelCase	:	str  )  ->			list[str]:
       if not isinstance(_UpperCAmelCase    ,_UpperCAmelCase  ):
              raise TypeError("""The parameter s type must be str."""  )

       return [s[i:] + s[:i] for i in range(len(_UpperCAmelCase  )  )]


def 	SCREAMING_SNAKE_CASE_					(  _UpperCAmelCase	:	str  )  ->			BWTTransformDict:
       if not isinstance(_UpperCAmelCase    ,_UpperCAmelCase  ):
              raise TypeError("""The parameter s type must be str."""  )
       if not s:
              raise ValueError("""The parameter s must not be empty."""  )

       _a    : List[Any]     					=all_rotations(_UpperCAmelCase  )
       rotations.sort()  # sort the list of rotations in alphabetically order
       # make a string composed of the last char of each rotation
       _a    : BWTTransformDict     					={
           "bwt_string": "".join([word[-1] for word in rotations]  ),
           "idx_original_string": rotations.index(_UpperCAmelCase  ),
       }
       return response


def 	SCREAMING_SNAKE_CASE_					(  _UpperCAmelCase	:	str    ,_UpperCAmelCase	:	int  )  ->			str:
       if not isinstance(_UpperCAmelCase    ,_UpperCAmelCase  ):
              raise TypeError("""The parameter bwt_string type must be str."""  )
       if not bwt_string:
              raise ValueError("""The parameter bwt_string must not be empty."""  )
       try:
              _a    : List[str]     					=int(_UpperCAmelCase  )
       except ValueError:
              raise TypeError(
                  """The parameter idx_original_string type must be int or passive"""
                  """ of cast to int."""  )
       if idx_original_string < 0:
              raise ValueError("""The parameter idx_original_string must not be lower than 0."""  )
       if idx_original_string >= len(_UpperCAmelCase  ):
              raise ValueError(
                  """The parameter idx_original_string must be lower than""" """ len(bwt_string)."""  )

       _a    : Optional[int]     					=[""""""] * len(_UpperCAmelCase  )
       for _ in range(len(_UpperCAmelCase  )  ):
              for i in range(len(_UpperCAmelCase  )  ):
                     _a    : int     					=bwt_string[i] + ordered_rotations[i]
              ordered_rotations.sort()
       return ordered_rotations[idx_original_string]


if __name__ == "__main__":
   A__:    Any					    =       '''Provide a string that I will generate its BWT transform: '''
   A__:    Union[str, Any]					    =       input(entry_msg).strip()
   A__:    Optional[int]					    =       bwt_transform(s)
   print(
       F"Burrows Wheeler transform for string '{s}' results "
       F"in '{result['bwt_string']}'"
   )
   A__:    Union[str, Any]					    =       reverse_bwt(result['''bwt_string'''], result['''idx_original_string'''])
   print(
       F"Reversing Burrows Wheeler transform for entry '{result['bwt_string']}' "
       F"we get original string '{original_string}'"
   )


