


from __future__ import annotations

__snake_case		=       tuple[int, int, int]
__snake_case		=       tuple[str, str, str]


# used alphabet --------------------------
# from string.ascii_uppercase
__snake_case		=       """ABCDEFGHIJKLMNOPQRSTUVWXYZ"""

# -------------------------- default selection --------------------------
# rotors --------------------------
__snake_case		=       """EGZWVONAHDCLFQMSIPJBYUKXTR"""
__snake_case		=       """FOBHMDKEXQNRAULPGSJVTYICZW"""
__snake_case		=       """ZJXESIUQLHAVRMDOYGTNFWPBKC"""
# reflector --------------------------
__snake_case		=       {
    """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 --------------------------
__snake_case		=       """RMDJXFUWGISLHVTCQNKYPBEZOA"""
__snake_case		=       """SGLCPQWZHKXAREONTFBVIYJUDM"""
__snake_case		=       """HVSICLTYKQUBXDWAJZOMFGPREN"""
__snake_case		=       """RZWQHFMVDBKICJLNTUXAGYPSOE"""
__snake_case		=       """LFKIJODBEGAMQPXVUHYSTCZRWN"""
__snake_case		=       """KOAEGVDHXPQZMLFTYWJNBRCIUS"""
def       A_   (   _lowerCAmelCase     :					int,     _lowerCAmelCase     :					List[Any],     _lowerCAmelCase     :					Optional[int]       ):






     """simple docstring"""

     if (unique_rotsel := len(set(_lowerCAmelCase       )       )) < 3:
          _a    	=				f'Please use 3 unique rotors (not {unique_rotsel})'
          raise Exception(_lowerCAmelCase       )

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

     # Validates string and returns dict
     _a    	=				_plugboard(_lowerCAmelCase       )

     return rotpos, rotsel, pbdict
def       A_   (   _lowerCAmelCase     :					Tuple       ):






     """simple docstring"""

     if not isinstance(_lowerCAmelCase,     _lowerCAmelCase       ):
          _a    	=				f'Plugboard setting isn\'t type string ({type(_lowerCAmelCase       )})'
          raise TypeError(_lowerCAmelCase       )
     elif len(_lowerCAmelCase       ) % 2 != 0:
          _a    	=				f'Odd number of symbols ({len(_lowerCAmelCase       )})'
          raise Exception(_lowerCAmelCase       )
     elif pbstring == "":
          return {}

     pbstring.replace(''' ''',     ''''''       )

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

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

     return pb
def       A_   (   _lowerCAmelCase     :					Tuple,     _lowerCAmelCase     :					Any,     _lowerCAmelCase     :					Optional[int] = (rotora, rotora, rotora),     _lowerCAmelCase     :					List[str] = "",     ):






     """simple docstring"""

     _a    	=				text.upper()
     _a	,      _a	,      _a    	=				_validator(
         _lowerCAmelCase,     _lowerCAmelCase,     plugb.upper()       )

     _a	,      _a	,      _a    	=				rotor_position
     _a	,      _a	,      _a    	=				rotor_selection
     rotorposa -= 1
     rotorposa -= 1
     rotorposa -= 1

     _a    	=				[]

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

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

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

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

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

               _a    	=				reflector[symbol]

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

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

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

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

     return "".join(_lowerCAmelCase       )


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

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



"""simple docstring"""






def       A_   (   _lowerCAmelCase     :					int = 10**12       ):






     """simple docstring"""

     _a    	=				1
     _a    	=				0

     _a    	=				1
     _a    	=				1

     while numerator <= 2 * min_total - 1:
          prev_numerator += 2 * numerator
          numerator += 2 * prev_numerator

          prev_denominator += 2 * denominator
          denominator += 2 * prev_denominator

     return (denominator + 1) // 2


if __name__ == "__main__":
   print(f'{solution() = }')