



from __future__ import annotations

a_						:     int	     =		tuple[int, int, int]
a_						:     Tuple	     =		tuple[str, str, str]


# used alphabet --------------------------
# from string.ascii_uppercase
a_						:     List[Any]	     =		'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

# -------------------------- default selection --------------------------
# rotors --------------------------
a_						:     Optional[int]	     =		'EGZWVONAHDCLFQMSIPJBYUKXTR'
a_						:     Any	     =		'FOBHMDKEXQNRAULPGSJVTYICZW'
a_						:     int	     =		'ZJXESIUQLHAVRMDOYGTNFWPBKC'
# reflector --------------------------
a_						:     Tuple	     =		{
    '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_						:     int	     =		'RMDJXFUWGISLHVTCQNKYPBEZOA'
a_						:     Optional[Any]	     =		'SGLCPQWZHKXAREONTFBVIYJUDM'
a_						:     Union[str, Any]	     =		'HVSICLTYKQUBXDWAJZOMFGPREN'
a_						:     Any	     =		'RZWQHFMVDBKICJLNTUXAGYPSOE'
a_						:     Optional[Any]	     =		'LFKIJODBEGAMQPXVUHYSTCZRWN'
a_						:     Optional[Any]	     =		'KOAEGVDHXPQZMLFTYWJNBRCIUS'

def     __lowercase(	UpperCAmelCase__   ,   UpperCAmelCase__   ,   UpperCAmelCase__ ):


      """simple docstring"""



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

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

      # Validates string and returns dict
      lowerCamelCase								=		_plugboard(UpperCAmelCase__ )

      return rotpos, rotsel, pbdict

def     __lowercase(	UpperCAmelCase__ ):


      """simple docstring"""



      if not isinstance(UpperCAmelCase__   ,   UpperCAmelCase__ ):
            lowerCamelCase								=		F"""Plugboard setting isn't type string ({type(UpperCAmelCase__ )})"""
            raise TypeError(UpperCAmelCase__ )
      elif len(UpperCAmelCase__ ) % 2 != 0:
            lowerCamelCase								=		F"""Odd number of symbols ({len(UpperCAmelCase__ )})"""
            raise Exception(UpperCAmelCase__ )
      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(UpperCAmelCase__ )
            elif i in tmppbl:
                  lowerCamelCase								=		F"""Duplicate symbol ({i})"""
                  raise Exception(UpperCAmelCase__ )
            else:
                  tmppbl.add(UpperCAmelCase__ )
      del tmppbl

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

      return pb

def     __lowercase(	UpperCAmelCase__   ,   UpperCAmelCase__   ,   UpperCAmelCase__ = (rotora, rotora, rotora)   ,   UpperCAmelCase__ = ""   ,   ):


      """simple docstring"""



      lowerCamelCase								=		text.upper()
      lowerCamelCase			,							lowerCamelCase			,							lowerCamelCase								=		_validator(
          UpperCAmelCase__   ,   UpperCAmelCase__   ,   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(UpperCAmelCase__ ) + rotorposa
                  lowerCamelCase								=		rotora[index % len(UpperCAmelCase__ )]

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

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

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

                  lowerCamelCase								=		reflector[symbol]

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

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

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

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

      return "".join(UpperCAmelCase__ )


if __name__ == "__main__":
     a_						:     int	     =		'This is my Python script that emulates the Enigma machine from WWII.'
     a_						:     str	     =		(1, 1, 1)
     a_						:     Optional[Any]	     =		'pictures'
     a_						:     Any	     =		(rotora, rotora, rotora)
     a_						:     Any	     =		enigma(message, rotor_pos, rotor_sel, pb)

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




from __future__ import annotations

from collections import deque
from collections.abc import Iterator
from dataclasses import dataclass





@dataclass
class    lowerCamelCase__  :
     """simple docstring"""



     _A       =			42
     _A       =			42





class    lowerCamelCase__  :
     """simple docstring"""



     def __init__(self				,			__a    ):






           '''simple docstring'''



           lowerCamelCase								=		[[] for _ in range(__a    )]
           lowerCamelCase								=		size







     def __getitem__(self				,			__a    ):






           '''simple docstring'''



           return iter(self._graph[vertex]    )







     @property
     def 						_a      (self    ):






           '''simple docstring'''



           return self._size







     def 						_a      (self				,			__a				,			__a				,			__a    ):






           '''simple docstring'''



           if weight not in (0, 1):
                 raise ValueError("Edge weight must be either 0 or 1."    )

           if to_vertex < 0 or to_vertex >= self.size:
                 raise ValueError("Vertex indexes must be in [0; size)."    )

           self._graph[from_vertex].append(Edge(__a				,			__a    )    )







     def 						_a      (self				,			__a				,			__a    ):






           '''simple docstring'''



           lowerCamelCase								=		deque([start_vertex]    )
           lowerCamelCase								=		[None] * self.size
           lowerCamelCase								=		0

           while queue:
                 lowerCamelCase								=		queue.popleft()
                 lowerCamelCase								=		distances[current_vertex]
                 if current_distance is None:
                       continue

                 for edge in self[current_vertex]:
                       lowerCamelCase								=		current_distance + edge.weight
                       lowerCamelCase								=		distances[edge.destination_vertex]
                       if (
                           isinstance(__a				,			__a    )
                           and new_distance >= dest_vertex_distance
                       ):
                             continue
                       lowerCamelCase								=		new_distance
                       if edge.weight == 0:
                             queue.appendleft(edge.destination_vertex    )
                       else:
                             queue.append(edge.destination_vertex    )

           if distances[finish_vertex] is None:
                 raise ValueError("No path from start_vertex to finish_vertex."    )

           return distances[finish_vertex]


if __name__ == "__main__":
     import doctest

     doctest.testmod()