



"""simple docstring"""






import os
import sys

from . import rsa_key_generator as rkg

_lowercase					:					List[Any] 		=		1_2_8
_lowercase					:					Union[str, Any] 		=		2_5_6






def 	snake_case__  (						__lowerCamelCase							:       str				,						__lowerCamelCase							:       int = DEFAULT_BLOCK_SIZE      ):
			"""simple docstring"""
			lowerCamelCase__						:						Optional[int]						      =message.encode('''ascii'''      )

			lowerCamelCase__						:						Dict						      =[]
			for block_start in range(0				,						len(__lowerCamelCase      )				,						__lowerCamelCase      ):
						lowerCamelCase__						:						List[Any]						      =0
						for i in range(__lowerCamelCase				,						min(block_start + block_size				,						len(__lowerCamelCase      )      )      ):
									block_int += message_bytes[i] * (BYTE_SIZE ** (i % block_size))
						block_ints.append(__lowerCamelCase      )
			return block_ints






def 	snake_case__  (						__lowerCamelCase							:       list[int]				,						__lowerCamelCase							:       int				,						__lowerCamelCase							:       int = DEFAULT_BLOCK_SIZE      ):
			"""simple docstring"""
			lowerCamelCase__						:						list[str]						      =[]
			for block_int in block_ints:
						lowerCamelCase__						:						list[str]						      =[]
						for i in range(block_size - 1				,						-1				,						-1      ):
									if len(__lowerCamelCase      ) + i < message_length:
												lowerCamelCase__						:						List[str]						      =block_int // (BYTE_SIZE**i)
												lowerCamelCase__						:						Optional[Any]						      =block_int % (BYTE_SIZE**i)
												block_message.insert(0				,						chr(__lowerCamelCase      )      )
						message.extend(__lowerCamelCase      )
			return "".join(__lowerCamelCase      )






def 	snake_case__  (						__lowerCamelCase							:       str				,						__lowerCamelCase							:       tuple[int, int]				,						__lowerCamelCase							:       int = DEFAULT_BLOCK_SIZE      ):
			"""simple docstring"""
			lowerCamelCase__						:						List[str]						      =[]
			lowerCamelCase__      ,  lowerCamelCase__						:						Union[str, Any]						      =key

			for block in get_blocks_from_text(__lowerCamelCase				,						__lowerCamelCase      ):
						encrypted_blocks.append(pow(__lowerCamelCase				,						__lowerCamelCase				,						__lowerCamelCase      )      )
			return encrypted_blocks






def 	snake_case__  (						__lowerCamelCase							:       list[int]				,						__lowerCamelCase							:       int				,						__lowerCamelCase							:       tuple[int, int]				,						__lowerCamelCase							:       int = DEFAULT_BLOCK_SIZE				,						):
			"""simple docstring"""
			lowerCamelCase__						:						Optional[Any]						      =[]
			lowerCamelCase__      ,  lowerCamelCase__						:						Dict						      =key
			for block in encrypted_blocks:
						decrypted_blocks.append(pow(__lowerCamelCase				,						__lowerCamelCase				,						__lowerCamelCase      )      )
			return get_text_from_blocks(__lowerCamelCase				,						__lowerCamelCase				,						__lowerCamelCase      )






def 	snake_case__  (						__lowerCamelCase							:       str      ):
			"""simple docstring"""
			with open(__lowerCamelCase      ) as fo:
						lowerCamelCase__						:						List[str]						      =fo.read()
			lowerCamelCase__      ,  lowerCamelCase__      ,  lowerCamelCase__						:						Dict						      =content.split(''','''      )
			return (int(__lowerCamelCase      ), int(__lowerCamelCase      ), int(__lowerCamelCase      ))






def 	snake_case__  (						__lowerCamelCase							:       str				,						__lowerCamelCase							:       str				,						__lowerCamelCase							:       str				,						__lowerCamelCase							:       int = DEFAULT_BLOCK_SIZE				,						):
			"""simple docstring"""
			lowerCamelCase__      ,  lowerCamelCase__      ,  lowerCamelCase__						:						str						      =read_key_file(__lowerCamelCase      )
			if key_size < block_size * 8:
						sys.exit(
						    '''ERROR: Block size is {} bits and key size is {} bits. The RSA cipher '''
						    '''requires the block size to be equal to or greater than the key size. '''
						    '''Either decrease the block size or use different keys.'''.format(
						        block_size * 8				,						__lowerCamelCase      )      )

			lowerCamelCase__						:						str						      =[str(__lowerCamelCase      ) for i in encrypt_message(__lowerCamelCase				,						(n, e)				,						__lowerCamelCase      )]

			lowerCamelCase__						:						Tuple						      =''','''.join(__lowerCamelCase      )
			lowerCamelCase__						:						Union[str, Any]						      =f'''{len(__lowerCamelCase      )}_{block_size}_{encrypted_content}'''
			with open(__lowerCamelCase				,						'''w'''      ) as fo:
						fo.write(__lowerCamelCase      )
			return encrypted_content






def 	snake_case__  (						__lowerCamelCase							:       str				,						__lowerCamelCase							:       str      ):
			"""simple docstring"""
			lowerCamelCase__      ,  lowerCamelCase__      ,  lowerCamelCase__						:						Tuple						      =read_key_file(__lowerCamelCase      )
			with open(__lowerCamelCase      ) as fo:
						lowerCamelCase__						:						Dict						      =fo.read()
			lowerCamelCase__      ,  lowerCamelCase__      ,  lowerCamelCase__						:						int						      =content.split('''_'''      )
			lowerCamelCase__						:						Dict						      =int(__lowerCamelCase      )
			lowerCamelCase__						:						List[str]						      =int(__lowerCamelCase      )

			if key_size < block_size * 8:
						sys.exit(
						    '''ERROR: Block size is {} bits and key size is {} bits. The RSA cipher '''
						    '''requires the block size to be equal to or greater than the key size. '''
						    '''Did you specify the correct key file and encrypted file?'''.format(
						        block_size * 8				,						__lowerCamelCase      )      )

			lowerCamelCase__						:						Optional[int]						      =[]
			for block in encrypted_message.split(''','''      ):
						encrypted_blocks.append(int(__lowerCamelCase      )      )

			return decrypt_message(__lowerCamelCase				,						__lowerCamelCase				,						(n, d)				,						__lowerCamelCase      )






def 	snake_case__  (						):
			"""simple docstring"""
			lowerCamelCase__						:						Optional[Any]						      ='''encrypted_file.txt'''
			lowerCamelCase__						:						List[Any]						      =input(R'''Encrypt\Decrypt [e\d]: '''      )

			if response.lower().startswith('''e'''      ):
						lowerCamelCase__						:						Any						      ='''encrypt'''
			elif response.lower().startswith('''d'''      ):
						lowerCamelCase__						:						Dict						      ='''decrypt'''

			if mode == "encrypt":
						if not os.path.exists('''rsa_pubkey.txt'''      ):
									rkg.make_key_files('''rsa'''				,						1024      )

						lowerCamelCase__						:						Tuple						      =input('''\nEnter message: '''      )
						lowerCamelCase__						:						List[str]						      ='''rsa_pubkey.txt'''
						print(f'''Encrypting and writing to {filename}...'''      )
						lowerCamelCase__						:						List[Any]						      =encrypt_and_write_to_file(__lowerCamelCase				,						__lowerCamelCase				,						__lowerCamelCase      )

						print('''\nEncrypted text:'''      )
						print(__lowerCamelCase      )

			elif mode == "decrypt":
						lowerCamelCase__						:						int						      ='''rsa_privkey.txt'''
						print(f'''Reading from {filename} and decrypting...'''      )
						lowerCamelCase__						:						Dict						      =read_from_file_and_decrypt(__lowerCamelCase				,						__lowerCamelCase      )
						print('''writing decryption to rsa_decryption.txt...'''      )
						with open('''rsa_decryption.txt'''				,						'''w'''      ) as dec:
									dec.write(__lowerCamelCase      )

						print('''\nDecryption:'''      )
						print(__lowerCamelCase      )


if __name__ == "__main__":
		main()







"""simple docstring"""




import math

import qiskit
from qiskit import Aer, ClassicalRegister, QuantumCircuit, QuantumRegister, execute



def 						UpperCAmelCase__ (					A__ = 1						,     A__ = 1 )   ->   qiskit.result.counts.Counts:




   """simple docstring"""
   if isinstance(A__						,     A__ ) or isinstance(A__						,     A__ ):
      raise TypeError("inputs must be integers." )
   if (bit_a < 0) or (bit_a < 0):
      raise ValueError("inputs must be positive." )
   if (math.floor(A__ ) != bit_a) or (math.floor(A__ ) != bit_a):
      raise ValueError("inputs must be exact integers." )
   if (bit_a > 1) or (bit_a > 1):
      raise ValueError("inputs must be less or equal to 1." )

   # build registers
   lowerCamelCase__						       =      QuantumRegister(2						,     "qr" )
   lowerCamelCase__						       =      ClassicalRegister(2						,     "cr" )

   lowerCamelCase__						       =      QuantumCircuit(A__						,     A__ )

   # entanglement the qubits
   quantum_circuit.h(1 )
   quantum_circuit.cx(1						,     0 )

   # send the information
   lowerCamelCase__						       =      str(A__ ) + str(A__ )

   if c_information == "11":
      quantum_circuit.x(1 )
      quantum_circuit.z(1 )
   elif c_information == "10":
      quantum_circuit.z(1 )
   elif c_information == "01":
      quantum_circuit.x(1 )
   else:
      quantum_circuit.i(1 )

   # unentangled the circuit
   quantum_circuit.cx(1						,     0 )
   quantum_circuit.h(1 )

   # measure the circuit
   quantum_circuit.measure(A__						,     A__ )

   lowerCamelCase__						       =      Aer.get_backend("aer_simulator" )
   lowerCamelCase__						       =      execute(A__						,     A__						,     shots=1000 )

   return job.result().get_counts(A__ )


if __name__ == "__main__":
     print(F'''Counts for classical state send: {superdense_coding(1,1)}''')




