






import math






def   UpperCamelCase  (       ):




     '''simple docstring'''






     __snake_case			:str          =						input("""Enter message: """  )
     __snake_case			:Optional[Any]          =						int(input(f'''Enter key [2-{len(snake_case__  ) - 1}]: '''  )  )
     __snake_case			:Any          =						input("""Encryption/Decryption [e/d]: """  )

     if mode.lower().startswith("""e"""  ):
          __snake_case			:int          =						encrypt_message(snake_case__	,snake_case__  )
     elif mode.lower().startswith("""d"""  ):
          __snake_case			:Optional[int]          =						decrypt_message(snake_case__	,snake_case__  )

     # Append pipe symbol (vertical bar) to identify spaces at the end.
     print(f'''Output:\n{text + '|'}'''  )






def   UpperCamelCase  (       snake_case__     :   int	,snake_case__     :   str  ):




     '''simple docstring'''






     __snake_case			:Union[str, Any]          =						[""""""] * key
     for col in range(snake_case__  ):
          __snake_case			:Dict          =						col
          while pointer < len(snake_case__  ):
               cipher_text[col] += message[pointer]
               pointer += key
     return "".join(snake_case__  )






def   UpperCamelCase  (       snake_case__     :   int	,snake_case__     :   str  ):




     '''simple docstring'''






     __snake_case			:List[Any]          =						math.ceil(len(snake_case__  ) / key  )
     __snake_case			:Union[str, Any]          =						key
     __snake_case			:Optional[int]          =						(num_cols * num_rows) - len(snake_case__  )
     __snake_case			:List[Any]          =						[""""""] * num_cols
     __snake_case			:Tuple          =						0
     __snake_case			:Optional[int]          =						0

     for symbol in message:
          plain_text[col] += symbol
          col += 1

          if (
              (col == num_cols)
              or (col == num_cols - 1)
              and (row >= num_rows - num_shaded_boxes)
          ):
               __snake_case			:Optional[Any]          =						0
               row += 1

     return "".join(snake_case__  )


if __name__ == "__main__":
     import doctest

     doctest.testmod()
     main()










import numpy as np
import qiskit






def   UpperCamelCase  (       snake_case__     :   int = 8	,snake_case__     :   int | None = None  ):




     '''simple docstring'''






     __snake_case			:Tuple          =						np.random.default_rng(seed=snake_case__  )

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

     # Quantum Circuit to simulate BB84
     __snake_case			:Optional[int]          =						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.
     __snake_case			:Optional[int]          =						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.
     __snake_case			:List[Any]          =						qiskit.execute(snake_case__	,snake_case__	,shots=1	,seed_simulator=snake_case__  )
     # Returns the result of measurement.
     __snake_case			:Tuple          =						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.
     __snake_case			:Any          =						"""""".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.
     __snake_case			:Dict          =						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()


