





"""simple docstring"""



import os
import string
import sys


a_			=      1 << 8

a_			=      {
    """tab""": ord("""\t"""),
    """newline""": ord("""\r"""),
    """esc""": 27,
    """up""": 65 + ARROW_KEY_FLAG,
    """down""": 66 + ARROW_KEY_FLAG,
    """right""": 67 + ARROW_KEY_FLAG,
    """left""": 68 + ARROW_KEY_FLAG,
    """mod_int""": 91,
    """undefined""": sys.maxsize,
    """interrupt""": 3,
    """insert""": 50,
    """delete""": 51,
    """pg_up""": 53,
    """pg_down""": 54,
}

a_			=      KEYMAP["""up"""]
a_			=      KEYMAP["""left"""]

if sys.platform == "win32":
       a_			=      []
       a_			=      {
           B"""\xe0H""": KEYMAP["""up"""] - ARROW_KEY_FLAG,
           B"""\x00H""": KEYMAP["""up"""] - ARROW_KEY_FLAG,
           B"""\xe0P""": KEYMAP["""down"""] - ARROW_KEY_FLAG,
           B"""\x00P""": KEYMAP["""down"""] - ARROW_KEY_FLAG,
           B"""\xe0M""": KEYMAP["""right"""] - ARROW_KEY_FLAG,
           B"""\x00M""": KEYMAP["""right"""] - ARROW_KEY_FLAG,
           B"""\xe0K""": KEYMAP["""left"""] - ARROW_KEY_FLAG,
           B"""\x00K""": KEYMAP["""left"""] - ARROW_KEY_FLAG,
       }

for i in range(10):
       a_			=      ord(str(i))







def 		__lowercase					(       )       ->List[Any]:



    '''simple docstring'''







    if os.name == "nt":
        import msvcrt

        __A   :						Optional[int]									=					'''mbcs'''
        # Flush the keyboard buffer
        while msvcrt.kbhit():
            msvcrt.getch()
        if len(snake_case_						) == 0:
            # Read the keystroke
            __A   :						Dict									=					msvcrt.getch()

            # If it is a prefix char, get second part
            if ch in (b"\x00", b"\xe0"):
                __A   :						Optional[Any]									=					ch + msvcrt.getch()
                # Translate actual Win chars to bullet char types
                try:
                    __A   :						List[Any]									=					chr(WIN_KEYMAP[cha]						)
                    WIN_CH_BUFFER.append(chr(KEYMAP['''mod_int''']						)						)
                    WIN_CH_BUFFER.append(snake_case_						)
                    if ord(snake_case_						) in (
                        KEYMAP["insert"] - 1 << 9,
                        KEYMAP["delete"] - 1 << 9,
                        KEYMAP["pg_up"] - 1 << 9,
                        KEYMAP["pg_down"] - 1 << 9,
                    ):
                        WIN_CH_BUFFER.append(chr(126						)						)
                    __A   :						List[Any]									=					chr(KEYMAP['''esc''']						)
                except KeyError:
                    __A   :						Any									=					cha[1]
            else:
                __A   :						Union[str, Any]									=					ch.decode(snake_case_						)
        else:
            __A   :						Union[str, Any]									=					WIN_CH_BUFFER.pop(0						)
    elif os.name == "posix":
        import termios
        import tty

        __A   :						List[Any]									=					sys.stdin.fileno()
        __A   :						str									=					termios.tcgetattr(snake_case_						)
        try:
            tty.setraw(snake_case_						)
            __A   :						List[Any]									=					sys.stdin.read(1						)
        finally:
            termios.tcsetattr(snake_case_    ,termios.TCSADRAIN    ,snake_case_						)
    return ch







def 		__lowercase					(       )       ->List[Any]:



    '''simple docstring'''







    __A   :						List[Any]									=					get_raw_chars()
    if ord(snake_case_						) in [KEYMAP["interrupt"], KEYMAP["newline"]]:
        return char

    elif ord(snake_case_						) == KEYMAP["esc"]:
        __A   :						List[Any]									=					get_raw_chars()
        if ord(snake_case_						) == KEYMAP["mod_int"]:
            __A   :						str									=					get_raw_chars()
            if ord(snake_case_						) >= KEYMAP["arrow_begin"] - ARROW_KEY_FLAG and ord(snake_case_						) <= KEYMAP["arrow_end"] - ARROW_KEY_FLAG:
                return chr(ord(snake_case_						) + ARROW_KEY_FLAG						)
            else:
                return KEYMAP["undefined"]
        else:
            return get_raw_chars()

    else:
        if char in string.printable:
            return char
        else:
            return KEYMAP["undefined"]











"""simple docstring"""



import numpy as np
import qiskit







def 		__lowercase					(       snake_case_  :  int = 8    ,snake_case_  :  int | None = None						)       ->str:



    '''simple docstring'''







    __A   :						str									=					np.random.default_rng(seed=snake_case_						)

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

    # Quantum Circuit to simulate BB84
    __A   :						Dict									=					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.
    __A   :						List[str]									=					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   :						List[str]									=					qiskit.execute(snake_case_    ,snake_case_    ,shots=1    ,seed_simulator=snake_case_						)
    # Returns the result of measurement.
    __A   :						Union[str, Any]									=					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.
    __A   :						int									=					''''''.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.
    __A   :						Union[str, Any]									=					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()




