




import random
import sys

from . import cryptomath_module as cryptomath

_lowerCamelCase			 =						(
    r' !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`'
    r'abcdefghijklmnopqrstuvwxyz{|}~'
)




def 					SCREAMING_SNAKE_CASE	(       __UpperCamelCase			:						int       ,     __UpperCamelCase			:						int       ,     __UpperCamelCase			:						str      )  ->							None:
    if mode == "encrypt":
        if key_a == 1:
            sys.exit(
                '''The affine cipher becomes weak when key '''
                '''A is set to 1. Choose different key'''      )
        if key_b == 0:
            sys.exit(
                '''The affine cipher becomes weak when key '''
                '''B is set to 0. Choose different key'''      )
    if key_a < 0 or key_b < 0 or key_b > len(__UpperCamelCase      ) - 1:
        sys.exit(
            '''Key A must be greater than 0 and key B must '''
            f'be between 0 and {len(__UpperCamelCase      ) - 1}.'      )
    if cryptomath.gcd(__UpperCamelCase       ,     len(__UpperCamelCase      )      ) != 1:
        sys.exit(
            f'Key A {key_a} and the symbol set size {len(__UpperCamelCase      )} '
            '''are not relatively prime. Choose a different key.'''      )




def 					SCREAMING_SNAKE_CASE	(       __UpperCamelCase			:						int       ,     __UpperCamelCase			:						str      )  ->							str:
    UpperCAmelCase_ ,							UpperCAmelCase_							 =     divmod(__UpperCamelCase       ,     len(__UpperCamelCase      )      )
    check_keys(__UpperCamelCase       ,     __UpperCamelCase       ,     '''encrypt'''      )
    UpperCAmelCase_							 =     ''''''
    for symbol in message:
        if symbol in SYMBOLS:
            UpperCAmelCase_							 =     SYMBOLS.find(__UpperCamelCase      )
            cipher_text += SYMBOLS[(sym_index * key_a + key_b) % len(__UpperCamelCase      )]
        else:
            cipher_text += symbol
    return cipher_text




def 					SCREAMING_SNAKE_CASE	(       __UpperCamelCase			:						int       ,     __UpperCamelCase			:						str      )  ->							str:
    UpperCAmelCase_ ,							UpperCAmelCase_							 =     divmod(__UpperCamelCase       ,     len(__UpperCamelCase      )      )
    check_keys(__UpperCamelCase       ,     __UpperCamelCase       ,     '''decrypt'''      )
    UpperCAmelCase_							 =     ''''''
    UpperCAmelCase_							 =     cryptomath.find_mod_inverse(__UpperCamelCase       ,     len(__UpperCamelCase      )      )
    for symbol in message:
        if symbol in SYMBOLS:
            UpperCAmelCase_							 =     SYMBOLS.find(__UpperCamelCase      )
            plain_text += SYMBOLS[
                (sym_index - key_b) * mod_inverse_of_key_a % len(__UpperCamelCase      )
            ]
        else:
            plain_text += symbol
    return plain_text




def 					SCREAMING_SNAKE_CASE	(       )  ->							int:
    while True:
        UpperCAmelCase_							 =     random.randint(2       ,     len(__UpperCamelCase      )      )
        UpperCAmelCase_							 =     random.randint(2       ,     len(__UpperCamelCase      )      )
        if cryptomath.gcd(__UpperCamelCase       ,     len(__UpperCamelCase      )      ) == 1 and key_b % len(__UpperCamelCase      ) != 0:
            return key_b * len(__UpperCamelCase      ) + key_b




def 					SCREAMING_SNAKE_CASE	(       )  ->							None:
    UpperCAmelCase_							 =     input('''Enter message: '''      ).strip()
    UpperCAmelCase_							 =     int(input('''Enter key [2000 - 9000]: '''      ).strip()      )
    UpperCAmelCase_							 =     input('''Encrypt/Decrypt [E/D]: '''      ).strip().lower()

    if mode.startswith('''e'''      ):
        UpperCAmelCase_							 =     '''encrypt'''
        UpperCAmelCase_							 =     encrypt_message(__UpperCamelCase       ,     __UpperCamelCase      )
    elif mode.startswith('''d'''      ):
        UpperCAmelCase_							 =     '''decrypt'''
        UpperCAmelCase_							 =     decrypt_message(__UpperCamelCase       ,     __UpperCamelCase      )
    print(f'\n{mode.title()}ed text: \n{translated}'      )


if __name__ == "__main__":
 import doctest

 doctest.testmod()
 # main()











import math

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




def 					SCREAMING_SNAKE_CASE	(       __UpperCamelCase			:						int = 1       ,     __UpperCamelCase			:						int = 1      )  ->							qiskit.result.counts.Counts:
    if isinstance(__UpperCamelCase       ,     __UpperCamelCase      ) or isinstance(__UpperCamelCase       ,     __UpperCamelCase      ):
        raise TypeError('''inputs must be integers.'''      )
    if (bit_a < 0) or (bit_a < 0):
        raise ValueError('''inputs must be positive.'''      )
    if (math.floor(__UpperCamelCase      ) != bit_a) or (math.floor(__UpperCamelCase      ) != 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
    UpperCAmelCase_							 =     QuantumRegister(2       ,     '''qr'''      )
    UpperCAmelCase_							 =     ClassicalRegister(2       ,     '''cr'''      )

    UpperCAmelCase_							 =     QuantumCircuit(__UpperCamelCase       ,     __UpperCamelCase      )

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

    # send the information
    UpperCAmelCase_							 =     str(__UpperCamelCase      ) + str(__UpperCamelCase      )

    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(__UpperCamelCase       ,     __UpperCamelCase      )

    UpperCAmelCase_							 =     Aer.get_backend('''aer_simulator'''      )
    UpperCAmelCase_							 =     execute(__UpperCamelCase       ,     __UpperCamelCase       ,     shots=1000      )

    return job.result().get_counts(__UpperCamelCase      )


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





