

'''simple docstring'''

from __future__ import annotations

A_       						=							tuple[int, int, int]
A_       						=							tuple[str, str, str]


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

# -------------------------- default selection --------------------------
# rotors --------------------------
A_       						=							"EGZWVONAHDCLFQMSIPJBYUKXTR"
A_       						=							"FOBHMDKEXQNRAULPGSJVTYICZW"
A_       						=							"ZJXESIUQLHAVRMDOYGTNFWPBKC"
# reflector --------------------------
A_       						=							{
    "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 --------------------------
A_       						=							"RMDJXFUWGISLHVTCQNKYPBEZOA"
A_       						=							"SGLCPQWZHKXAREONTFBVIYJUDM"
A_       						=							"HVSICLTYKQUBXDWAJZOMFGPREN"
A_       						=							"RZWQHFMVDBKICJLNTUXAGYPSOE"
A_       						=							"LFKIJODBEGAMQPXVUHYSTCZRWN"
A_       						=							"KOAEGVDHXPQZMLFTYWJNBRCIUS"





def    A_  ( snake_case      ,       snake_case      ,       snake_case ):
  # Checks if there are 3 unique rotors

  if (unique_rotsel := len(set(snake_case ) )) < 3:
    SCREAMING_SNAKE_CASE:List[str]						      =					F'''Please use 3 unique rotors (not {unique_rotsel})'''
    raise Exception(snake_case )

  # Checks if rotor positions are valid
  SCREAMING_SNAKE_CASE      ,    SCREAMING_SNAKE_CASE      ,    SCREAMING_SNAKE_CASE:Tuple						      =					rotpos
  if not 0 < rotorposa <= len(snake_case ):
    SCREAMING_SNAKE_CASE:Any						      =					F'''First rotor position is not within range of 1..26 ({rotorposa}'''
    raise ValueError(snake_case )
  if not 0 < rotorposa <= len(snake_case ):
    SCREAMING_SNAKE_CASE:Optional[int]						      =					F'''Second rotor position is not within range of 1..26 ({rotorposa})'''
    raise ValueError(snake_case )
  if not 0 < rotorposa <= len(snake_case ):
    SCREAMING_SNAKE_CASE:Optional[int]						      =					F'''Third rotor position is not within range of 1..26 ({rotorposa})'''
    raise ValueError(snake_case )

  # Validates string and returns dict
  SCREAMING_SNAKE_CASE:Tuple						      =					_plugboard(snake_case )

  return rotpos, rotsel, pbdict





def    A_  ( snake_case ):

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

  pbstring.replace(" "      ,       "" )

  # Checks if all characters are unique
  SCREAMING_SNAKE_CASE:str						      =					set()
  for i in pbstring:
    if i not in abc:
      SCREAMING_SNAKE_CASE:List[str]						      =					F'''\'{i}\' not in list of symbols'''
      raise Exception(snake_case )
    elif i in tmppbl:
      SCREAMING_SNAKE_CASE:Optional[int]						      =					F'''Duplicate symbol ({i})'''
      raise Exception(snake_case )
    else:
      tmppbl.add(snake_case )
  del tmppbl

  # Created the dictionary
  SCREAMING_SNAKE_CASE:Tuple						      =					{}
  for j in range(0      ,       len(snake_case ) - 1      ,       2 ):
    SCREAMING_SNAKE_CASE:List[str]						      =					pbstring[j + 1]
    SCREAMING_SNAKE_CASE:int						      =					pbstring[j]

  return pb





def    A_  ( snake_case      ,       snake_case      ,       snake_case = (rotora, rotora, rotora)      ,       snake_case = ""      ,       ):
  SCREAMING_SNAKE_CASE:Tuple						      =					text.upper()
  SCREAMING_SNAKE_CASE      ,    SCREAMING_SNAKE_CASE      ,    SCREAMING_SNAKE_CASE:Optional[int]						      =					_validator(
      snake_case      ,       snake_case      ,       plugb.upper() )

  SCREAMING_SNAKE_CASE      ,    SCREAMING_SNAKE_CASE      ,    SCREAMING_SNAKE_CASE:List[str]						      =					rotor_position
  SCREAMING_SNAKE_CASE      ,    SCREAMING_SNAKE_CASE      ,    SCREAMING_SNAKE_CASE:List[str]						      =					rotor_selection
  rotorposa -= 1
  rotorposa -= 1
  rotorposa -= 1

  SCREAMING_SNAKE_CASE:Dict						      =					[]

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

      # rotor ra --------------------------
      SCREAMING_SNAKE_CASE:Any						      =					abc.index(snake_case ) + rotorposa
      SCREAMING_SNAKE_CASE:List[Any]						      =					rotora[index % len(snake_case )]

      # rotor rb --------------------------
      SCREAMING_SNAKE_CASE:str						      =					abc.index(snake_case ) + rotorposa
      SCREAMING_SNAKE_CASE:str						      =					rotora[index % len(snake_case )]

      # rotor rc --------------------------
      SCREAMING_SNAKE_CASE:Tuple						      =					abc.index(snake_case ) + rotorposa
      SCREAMING_SNAKE_CASE:Dict						      =					rotora[index % len(snake_case )]

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

      SCREAMING_SNAKE_CASE:Dict						      =					reflector[symbol]

      # 2nd rotors
      SCREAMING_SNAKE_CASE:Optional[int]						      =					abc[rotora.index(snake_case ) - rotorposa]
      SCREAMING_SNAKE_CASE:int						      =					abc[rotora.index(snake_case ) - rotorposa]
      SCREAMING_SNAKE_CASE:Dict						      =					abc[rotora.index(snake_case ) - rotorposa]

      # 2nd plugboard
      if symbol in plugboard:
        SCREAMING_SNAKE_CASE:Dict						      =					plugboard[symbol]

      # moves/resets rotor positions
      rotorposa += 1
      if rotorposa >= len(snake_case ):
        SCREAMING_SNAKE_CASE:int						      =					0
        rotorposa += 1
      if rotorposa >= len(snake_case ):
        SCREAMING_SNAKE_CASE:List[Any]						      =					0
        rotorposa += 1
      if rotorposa >= len(snake_case ):
        SCREAMING_SNAKE_CASE:Dict						      =					0

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

  return "".join(snake_case )


if __name__ == "__main__":
    A_       						=							"This is my Python script that emulates the Enigma machine from WWII."
    A_       						=							(1, 1, 1)
    A_       						=							"pictures"
    A_       						=							(rotora, rotora, rotora)
    A_       						=							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_  ( snake_case ):
  SCREAMING_SNAKE_CASE:Dict						      =					(1 + 24 * n) ** 0.5
  return ((1 + root) / 6) % 1 == 0





def    A_  ( snake_case = 5000 ):
  SCREAMING_SNAKE_CASE:int						      =					[(i * (3 * i - 1)) // 2 for i in range(1      ,       snake_case )]
  for i, pentagonal_i in enumerate(snake_case ):
    for j in range(snake_case      ,       len(snake_case ) ):
      SCREAMING_SNAKE_CASE:int						      =					pentagonal_nums[j]
      SCREAMING_SNAKE_CASE:Any						      =					pentagonal_i + pentagonal_j
      SCREAMING_SNAKE_CASE:int						      =					pentagonal_j - pentagonal_i
      if is_pentagonal(snake_case ) and is_pentagonal(snake_case ):
        return b

  return -1


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






