from collections.abc import Callable
from math import pi, sqrt
from random import uniform
from statistics import mean






def 				__lowerCamelCase		(						lowerCAmelCase__     ):

       # A local function to see if a dot lands in the circle.
       def is_in_circle(lowerCAmelCase__     ,  lowerCAmelCase__     ) -> bool:
              lowerCAmelCase__					     = sqrt((x**2) + (y**2)     )
              # Our circle has a radius of 1, so a distance
              # greater than 1 would land outside the circle.
              return distance_from_centre <= 1

       # The proportion of guesses that landed in the circle
       lowerCAmelCase__					     = mean(
           int(is_in_circle(uniform(-1.0     ,  1.0     )     ,  uniform(-1.0     ,  1.0     )     )     )
           for _ in range(lowerCAmelCase__     )     )
       # The ratio of the area for circle to square is pi/4.
       lowerCAmelCase__					     = proportion * 4
       print(F"""The estimated value of pi is {pi_estimate}"""     )
       print(F"""The numpy value of pi is {pi}"""     )
       print(F"""The total error is {abs(pi - pi_estimate     )}"""     )






def 				__lowerCamelCase		(						lowerCAmelCase__     ,  lowerCAmelCase__     ,  lowerCAmelCase__ = 0.0     ,  lowerCAmelCase__ = 1.0     ,  ):
       return mean(
           function_to_integrate(uniform(lowerCAmelCase__     ,  lowerCAmelCase__     )     ) for _ in range(lowerCAmelCase__     )     ) * (max_value - min_value)






def 				__lowerCamelCase		(						lowerCAmelCase__     ,  lowerCAmelCase__ = 0.0     ,  lowerCAmelCase__ = 1.0     ):

       def identity_function(lowerCAmelCase__     ) -> float:
              return x

       lowerCAmelCase__					     = area_under_curve_estimator(
           lowerCAmelCase__     ,  lowerCAmelCase__     ,  lowerCAmelCase__     ,  lowerCAmelCase__     )
       lowerCAmelCase__					     = (max_value * max_value - min_value * min_value) / 2

       print('******************'     )
       print(F"""Estimating area under y=x where x varies from {min_value} to {max_value}"""     )
       print(F"""Estimated value is {estimated_value}"""     )
       print(F"""Expected value is {expected_value}"""     )
       print(F"""Total error is {abs(estimated_value - expected_value     )}"""     )
       print('******************'     )






def 				__lowerCamelCase		(						lowerCAmelCase__     ):

       def function_to_integrate(lowerCAmelCase__     ) -> float:
              return sqrt(4.0 - x * x     )

       lowerCAmelCase__					     = area_under_curve_estimator(
           lowerCAmelCase__     ,  lowerCAmelCase__     ,  0.0     ,  2.0     )

       print('******************'     )
       print('Estimating pi using area_under_curve_estimator'     )
       print(F"""Estimated value is {estimated_value}"""     )
       print(F"""Expected value is {pi}"""     )
       print(F"""Total error is {abs(estimated_value - pi     )}"""     )
       print('******************'     )


if __name__ == "__main__":
    import doctest

    doctest.testmod()

from __future__ import annotations

lowerCAmelCase__     						=			tuple[int, int, int]
lowerCAmelCase__     						=			tuple[str, str, str]


# used alphabet --------------------------
# from string.ascii_uppercase
lowerCAmelCase__     						=			'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

# -------------------------- default selection --------------------------
# rotors --------------------------
lowerCAmelCase__     						=			'EGZWVONAHDCLFQMSIPJBYUKXTR'
lowerCAmelCase__     						=			'FOBHMDKEXQNRAULPGSJVTYICZW'
lowerCAmelCase__     						=			'ZJXESIUQLHAVRMDOYGTNFWPBKC'
# reflector --------------------------
lowerCAmelCase__     						=			{
    'A': 'N',
    'N': 'A',
    'B': 'O',
    'O': 'B',
    'C': 'P',
    'P': 'C',
    'D': 'Q',
    'Q': 'D',
    'E': 'R',
    'R': 'E',
    'F': 'S',
    'S': 'F',
    'G': 'T',
    'T': 'G',
    'H': 'U',
    'U': 'H',
    'I': 'V',
    'V': 'I',
    'J': 'W',
    'W': 'J',
    'K': 'X',
    'X': 'K',
    'L': 'Y',
    'Y': 'L',
    'M': 'Z',
    'Z': 'M',
}

# -------------------------- extra rotors --------------------------
lowerCAmelCase__     						=			'RMDJXFUWGISLHVTCQNKYPBEZOA'
lowerCAmelCase__     						=			'SGLCPQWZHKXAREONTFBVIYJUDM'
lowerCAmelCase__     						=			'HVSICLTYKQUBXDWAJZOMFGPREN'
lowerCAmelCase__     						=			'RZWQHFMVDBKICJLNTUXAGYPSOE'
lowerCAmelCase__     						=			'LFKIJODBEGAMQPXVUHYSTCZRWN'
lowerCAmelCase__     						=			'KOAEGVDHXPQZMLFTYWJNBRCIUS'






def 				__lowerCamelCase		(						lowerCAmelCase__     ,  lowerCAmelCase__     ,  lowerCAmelCase__     ):
       # Checks if there are 3 unique rotors

       if (unique_rotsel := len(set(lowerCAmelCase__     )     )) < 3:
              lowerCAmelCase__					     = F"""Please use 3 unique rotors (not {unique_rotsel})"""
              raise Exception(lowerCAmelCase__     )

       # Checks if rotor positions are valid
       lowerCAmelCase__     , lowerCAmelCase__     , lowerCAmelCase__					     = rotpos
       if not 0 < rotorposa <= len(lowerCAmelCase__     ):
              lowerCAmelCase__					     = F"""First rotor position is not within range of 1..26 ({rotorposa}"""
              raise ValueError(lowerCAmelCase__     )
       if not 0 < rotorposa <= len(lowerCAmelCase__     ):
              lowerCAmelCase__					     = F"""Second rotor position is not within range of 1..26 ({rotorposa})"""
              raise ValueError(lowerCAmelCase__     )
       if not 0 < rotorposa <= len(lowerCAmelCase__     ):
              lowerCAmelCase__					     = F"""Third rotor position is not within range of 1..26 ({rotorposa})"""
              raise ValueError(lowerCAmelCase__     )

       # Validates string and returns dict
       lowerCAmelCase__					     = _plugboard(lowerCAmelCase__     )

       return rotpos, rotsel, pbdict






def 				__lowerCamelCase		(						lowerCAmelCase__     ):

       # tests the input string if it
       # a) is type string
       # b) has even length (so pairs can be made)
       if not isinstance(lowerCAmelCase__     ,  lowerCAmelCase__     ):
              lowerCAmelCase__					     = F"""Plugboard setting isn't type string ({type(lowerCAmelCase__     )})"""
              raise TypeError(lowerCAmelCase__     )
       elif len(lowerCAmelCase__     ) % 2 != 0:
              lowerCAmelCase__					     = F"""Odd number of symbols ({len(lowerCAmelCase__     )})"""
              raise Exception(lowerCAmelCase__     )
       elif pbstring == "":
              return {}

       pbstring.replace(' '     ,  ''     )

       # Checks if all characters are unique
       lowerCAmelCase__					     = set()
       for i in pbstring:
              if i not in abc:
                     lowerCAmelCase__					     = F"""'{i}' not in list of symbols"""
                     raise Exception(lowerCAmelCase__     )
              elif i in tmppbl:
                     lowerCAmelCase__					     = F"""Duplicate symbol ({i})"""
                     raise Exception(lowerCAmelCase__     )
              else:
                     tmppbl.add(lowerCAmelCase__     )
       del tmppbl

       # Created the dictionary
       lowerCAmelCase__					     = {}
       for j in range(0     ,  len(lowerCAmelCase__     ) - 1     ,  2     ):
              lowerCAmelCase__					     = pbstring[j + 1]
              lowerCAmelCase__					     = pbstring[j]

       return pb






def 				__lowerCamelCase		(						lowerCAmelCase__     ,  lowerCAmelCase__     ,  lowerCAmelCase__ = (rotora, rotora, rotora)     ,  lowerCAmelCase__ = ""     ,  ):
       lowerCAmelCase__					     = text.upper()
       lowerCAmelCase__     , lowerCAmelCase__     , lowerCAmelCase__					     = _validator(
           lowerCAmelCase__     ,  lowerCAmelCase__     ,  plugb.upper()     )

       lowerCAmelCase__     , lowerCAmelCase__     , lowerCAmelCase__					     = rotor_position
       lowerCAmelCase__     , lowerCAmelCase__     , lowerCAmelCase__					     = rotor_selection
       rotorposa -= 1
       rotorposa -= 1
       rotorposa -= 1

       lowerCAmelCase__					     = []

       # encryption/decryption process --------------------------
       for symbol in text:
              if symbol in abc:
                     # 1st plugboard --------------------------
                     if symbol in plugboard:
                            lowerCAmelCase__					     = plugboard[symbol]

                     # rotor ra --------------------------
                     lowerCAmelCase__					     = abc.index(lowerCAmelCase__     ) + rotorposa
                     lowerCAmelCase__					     = rotora[index % len(lowerCAmelCase__     )]

                     # rotor rb --------------------------
                     lowerCAmelCase__					     = abc.index(lowerCAmelCase__     ) + rotorposa
                     lowerCAmelCase__					     = rotora[index % len(lowerCAmelCase__     )]

                     # rotor rc --------------------------
                     lowerCAmelCase__					     = abc.index(lowerCAmelCase__     ) + rotorposa
                     lowerCAmelCase__					     = rotora[index % len(lowerCAmelCase__     )]

                     # reflector --------------------------
                     # this is the reason you don't need another machine to decipher

                     lowerCAmelCase__					     = reflector[symbol]

                     # 2nd rotors
                     lowerCAmelCase__					     = abc[rotora.index(lowerCAmelCase__     ) - rotorposa]
                     lowerCAmelCase__					     = abc[rotora.index(lowerCAmelCase__     ) - rotorposa]
                     lowerCAmelCase__					     = abc[rotora.index(lowerCAmelCase__     ) - rotorposa]

                     # 2nd plugboard
                     if symbol in plugboard:
                            lowerCAmelCase__					     = plugboard[symbol]

                     # moves/resets rotor positions
                     rotorposa += 1
                     if rotorposa >= len(lowerCAmelCase__     ):
                            lowerCAmelCase__					     = 0
                            rotorposa += 1
                     if rotorposa >= len(lowerCAmelCase__     ):
                            lowerCAmelCase__					     = 0
                            rotorposa += 1
                     if rotorposa >= len(lowerCAmelCase__     ):
                            lowerCAmelCase__					     = 0

        # else:
        #    pass
        #    Error could be also raised
        #    raise ValueError(
        #       'Invalid symbol('+repr(symbol)+')')
              result.append(lowerCAmelCase__     )

       return "".join(lowerCAmelCase__     )


if __name__ == "__main__":
    lowerCAmelCase__     						=			'This is my Python script that emulates the Enigma machine from WWII.'
    lowerCAmelCase__     						=			(1, 1, 1)
    lowerCAmelCase__     						=			'pictures'
    lowerCAmelCase__     						=			(rotora, rotora, rotora)
    lowerCAmelCase__     						=			enigma(message, rotor_pos, rotor_sel, pb)

    print('Encrypted message:', en)
    print('Decrypted message:', enigma(en, rotor_pos, rotor_sel, pb))
