


"""simple docstring"""



from sympy import diff, lambdify, symbols
from sympy.functions import *  # noqa: F403







def     __lowerCAmelCase		(		lowercase    :    str		,				lowercase    :    complex		,				lowercase    :    str = "x"		,				lowercase    :    float = 10**-10		,				lowercase    :    int = 1		,				)      ->		complex:


    """simple docstring"""





    snake_case       : Any    =       symbols(lowercase					)
    snake_case       : Any    =       lambdify(lowercase		,				lowercase					)
    snake_case       : Tuple    =       lambdify(lowercase		,				diff(lowercase		,				lowercase					)					)

    snake_case       : Optional[Any]    =       starting_point

    while True:
        if diff_function(lowercase					) != 0:
            snake_case       : Dict    =       prev_guess - multiplicity * func(lowercase					) / diff_function(
                lowercase					)
        else:
            raise ZeroDivisionError("Could not find root"					) from None

        # Precision is checked by comparing the difference of consecutive guesses
        if abs(next_guess - prev_guess					) < precision:
            return next_guess

        snake_case       : int    =       next_guess


# Let's Execute
if __name__ == "__main__":
  # Find root of trigonometric function
  # Find value of pi
  print(F'''The root of sin(x) = 0 is {newton_raphson("sin(x)", 2)}''')

  # Find root of polynomial
  # Find fourth Root of 5
  print(F'''The root of x**4 - 5 = 0 is {newton_raphson("x**4 -5", 0.4 +5j)}''')

  # Find value of e
  print(
      """The root of log(y) - 1 = 0 is """,
      F'''{newton_raphson("log(y) - 1", 2, variable="y")}''',
  )

  # Exponential Roots
  print(
      """The root of exp(x) - 1 = 0 is""",
      F'''{newton_raphson("exp(x) - 1", 10, precision=0.0_05)}''',
  )

  # Find root of cos(x)
  print(F'''The root of cos(x) = 0 is {newton_raphson("cos(x)", 0)}''')









"""simple docstring"""



__snake_case       =       """ABCDEFGHIJKLMNOPQRSTUVWXYZ"""







def     __lowerCAmelCase		(		)      ->		None:


    """simple docstring"""





    snake_case       : str    =       input("Enter message: "					)
    snake_case       : Tuple    =       input("Enter key [alphanumeric]: "					)
    snake_case       : Union[str, Any]    =       input("Encrypt/Decrypt [e/d]: "					)

    if mode.lower().startswith("e"					):
        snake_case       : str    =       "encrypt"
        snake_case       : Optional[int]    =       encrypt_message(lowercase		,				lowercase					)
    elif mode.lower().startswith("d"					):
        snake_case       : List[Any]    =       "decrypt"
        snake_case       : Tuple    =       decrypt_message(lowercase		,				lowercase					)

    print(F'\n{mode.title()}ed message:'					)
    print(lowercase					)







def     __lowerCAmelCase		(		lowercase    :    str		,				lowercase    :    str					)      ->		str:


    """simple docstring"""





    return translate_message(lowercase		,				lowercase		,				"encrypt"					)







def     __lowerCAmelCase		(		lowercase    :    str		,				lowercase    :    str					)      ->		str:


    """simple docstring"""





    return translate_message(lowercase		,				lowercase		,				"decrypt"					)







def     __lowerCAmelCase		(		lowercase    :    str		,				lowercase    :    str		,				lowercase    :    str					)      ->		str:


    """simple docstring"""





    snake_case       : List[Any]    =       []
    snake_case       : List[str]    =       0
    snake_case       : List[Any]    =       key.upper()

    for symbol in message:
        snake_case       : Optional[int]    =       LETTERS.find(symbol.upper()					)
        if num != -1:
            if mode == "encrypt":
                num += LETTERS.find(key[key_index]					)
            elif mode == "decrypt":
                num -= LETTERS.find(key[key_index]					)

            num %= len(lowercase					)

            if symbol.isupper():
                translated.append(LETTERS[num]					)
            elif symbol.islower():
                translated.append(LETTERS[num].lower()					)

            key_index += 1
            if key_index == len(lowercase					):
                snake_case       : List[str]    =       0
        else:
            translated.append(lowercase					)
    return "".join(lowercase					)


if __name__ == "__main__":
  main()





