





'''simple docstring'''


import numpy as np
import qiskit


def 		__a(SCREAMING_SNAKE_CASE_     :    Tuple = 8						,				SCREAMING_SNAKE_CASE_     :    int = None			):



    '''simple docstring'''





    _lowerCAmelCase			=					np.random.default_rng(seed=snake_case__			)

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

    # Quantum Circuit to simulate BB84
    _lowerCAmelCase			=					qiskit.QuantumCircuit(snake_case__						,				name="BB84"			)

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

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

    bbaa_circ.barrier()
    bbaa_circ.measure_all()

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

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

    # Get final key. Pad with 0 if too short, otherwise truncate.
    _lowerCAmelCase			=					gen_key[:key_len] if len(snake_case__			) >= key_len else gen_key.ljust(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"""




def     a__ (				snake_case__       , snake_case__ = False				)						->					str:

			if not isinstance(snake_case__       , snake_case__				):
						lowerCamelCase			      =					F'Expected string as input, found {type(snake_case__				)}'
						raise ValueError(snake_case__				)
			if not isinstance(snake_case__       , snake_case__				):
						lowerCamelCase			      =					F'Expected boolean as use_pascal parameter, found {type(snake_case__				)}'
						raise ValueError(snake_case__				)

			lowerCamelCase			      =					input_str.split("""_"""				)

			lowerCamelCase			      =					0 if use_pascal else 1

			lowerCamelCase			      =					words[start_index:]

			lowerCamelCase			      =					[word[0].upper() + word[1:] for word in words_to_capitalize]

			lowerCamelCase			      =					"""""" if use_pascal else words[0]

			return "".join([initial_word, *capitalized_words]				)


if __name__ == "__main__":
					from doctest import testmod

					testmod()



