'''simple docstring'''


import numpy as np
import qiskit

def   A_      (       SCREAMING_SNAKE_CASE_ = 8 ,	SCREAMING_SNAKE_CASE_ = None						)			->str:
  lowercase_     =       np.random.default_rng(seed=SCREAMING_SNAKE_CASE_						)

  # Roughly 25% of the qubits will contribute to the key.
  # So we take more than we need.
  lowercase_     =       6 * key_len
  # Measurement basis for Alice's qubits.
  lowercase_     =       rng.integers(2 ,	size=SCREAMING_SNAKE_CASE_						)
  # The set of states Alice will prepare.
  lowercase_     =       rng.integers(2 ,	size=SCREAMING_SNAKE_CASE_						)
  # Measurement basis for Bob's qubits.
  lowercase_     =       rng.integers(2 ,	size=SCREAMING_SNAKE_CASE_						)

  # Quantum Circuit to simulate BB84
  lowercase_     =       qiskit.QuantumCircuit(SCREAMING_SNAKE_CASE_ ,	name="""BB84"""						)

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

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

  bbaa_circ.barrier()
  bbaa_circ.measure_all()

  # Simulate the quantum circuit.
  lowercase_     =       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.
  lowercase_     =       qiskit.execute(SCREAMING_SNAKE_CASE_ ,	SCREAMING_SNAKE_CASE_ ,	shots=1 ,	seed_simulator=SCREAMING_SNAKE_CASE_						)
  # Returns the result of measurement.
  lowercase_     =       job.result().get_counts(SCREAMING_SNAKE_CASE_						).most_frequent()

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

  # Get final key. Pad with 0 if too short, otherwise truncate.
  lowercase_     =       gen_key[:key_len] if len(SCREAMING_SNAKE_CASE_						) >= key_len else gen_key.ljust(SCREAMING_SNAKE_CASE_ ,	"""0"""						)
  return key


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

       testmod()


'''simple docstring'''


from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


__snake_case						  =		{
    """configuration_git""": ["""GIT_PRETRAINED_CONFIG_ARCHIVE_MAP""", """GitConfig""", """GitVisionConfig"""],
    """processing_git""": ["""GitProcessor"""],
}

try:
       if not is_torch_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       __snake_case						  =		[
           """GIT_PRETRAINED_MODEL_ARCHIVE_LIST""",
           """GitForCausalLM""",
           """GitModel""",
           """GitPreTrainedModel""",
           """GitVisionModel""",
       ]

if TYPE_CHECKING:
       from .configuration_git import GIT_PRETRAINED_CONFIG_ARCHIVE_MAP, GitConfig, GitVisionConfig
       from .processing_git import GitProcessor

       try:
              if not is_torch_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .modeling_git import (
                  GIT_PRETRAINED_MODEL_ARCHIVE_LIST,
                  GitForCausalLM,
                  GitModel,
                  GitPreTrainedModel,
                  GitVisionModel,
              )

else:
       import sys

       __snake_case						  =		_LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)

