

'''simple docstring'''






import numpy as np
import qiskit


def 						_A	(       A__ = 8	,							A__ = None ):






 """simple docstring"""



 __lowercase				    =					np.random.default_rng(seed=A__ )

 # 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=A__ )
 # The set of states Alice will prepare.
 __lowercase				    =					rng.integers(2	,							size=A__ )
 # Measurement basis for Bob's qubits.
 __lowercase				    =					rng.integers(2	,							size=A__ )

 # Quantum Circuit to simulate BB84
 __lowercase				    =					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.
 __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(A__	,							A__	,							shots=1	,							seed_simulator=A__ )
 # Returns the result of measurement.
 __lowercase				    =					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.
 __lowercase				    =					''''''.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.
 __lowercase				    =					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 collections.abc import Callable

import numpy as np



def  lowerCamelCase__						(     __snake_case,	__snake_case,	__snake_case,	__snake_case,	__snake_case      )				->						np.array:


					"""simple docstring"""





					_UpperCamelCase									=    int(np.ceil((x_end - xa) / step_size      )      )
					_UpperCamelCase									=    np.zeros((n + 1,)      )
					_UpperCamelCase									=    ya
					_UpperCamelCase									=    xa

					for k in range(__snake_case      ):
										_UpperCamelCase									=    y[k] + step_size * ode_func(__snake_case,	y[k]      )
										_UpperCamelCase									=    y[k] + (
										    (step_size / 2) * (ode_func(__snake_case,	y[k]      ) + ode_func(x + step_size,	__snake_case      ))
										)
										x += step_size

					return y


if __name__ == "__main__":
				import doctest

				doctest.testmod()






