
'''simple docstring'''







from __future__ import annotations

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


# used alphabet --------------------------
# from string.ascii_uppercase
_lowercase			:  str   							=	"ABCDEFGHIJKLMNOPQRSTUVWXYZ"

# -------------------------- default selection --------------------------
# rotors --------------------------
_lowercase			:  Any   							=	"EGZWVONAHDCLFQMSIPJBYUKXTR"
_lowercase			:  Any   							=	"FOBHMDKEXQNRAULPGSJVTYICZW"
_lowercase			:  Dict   							=	"ZJXESIUQLHAVRMDOYGTNFWPBKC"
# reflector --------------------------
_lowercase			:  Dict   							=	{
    "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 --------------------------
_lowercase			:  Union[str, Any]   							=	"RMDJXFUWGISLHVTCQNKYPBEZOA"
_lowercase			:  Dict   							=	"SGLCPQWZHKXAREONTFBVIYJUDM"
_lowercase			:  Union[str, Any]   							=	"HVSICLTYKQUBXDWAJZOMFGPREN"
_lowercase			:  Any   							=	"RZWQHFMVDBKICJLNTUXAGYPSOE"
_lowercase			:  List[Any]   							=	"LFKIJODBEGAMQPXVUHYSTCZRWN"
_lowercase			:  int   							=	"KOAEGVDHXPQZMLFTYWJNBRCIUS"
def  snake_case_		(    __SCREAMING_SNAKE_CASE :			RotorPositionT				,				__SCREAMING_SNAKE_CASE :			RotorSelectionT				,				__SCREAMING_SNAKE_CASE :			str							):



						"""simple docstring"""





						if (unique_rotsel := len(set(__SCREAMING_SNAKE_CASE							)							)) < 3:
												lowercase_     :					Any													=	F'''Please use 3 unique rotors (not {unique_rotsel})'''
												raise Exception(__SCREAMING_SNAKE_CASE							)

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

						# Validates string and returns dict
						lowercase_     :					str													=	_plugboard(__SCREAMING_SNAKE_CASE							)

						return rotpos, rotsel, pbdict
def  snake_case_		(    __SCREAMING_SNAKE_CASE :			str							):



						"""simple docstring"""





						if not isinstance(__SCREAMING_SNAKE_CASE				,				__SCREAMING_SNAKE_CASE							):
												lowercase_     :					Optional[Any]													=	F'''Plugboard setting isn\'t type string ({type(__SCREAMING_SNAKE_CASE							)})'''
												raise TypeError(__SCREAMING_SNAKE_CASE							)
						elif len(__SCREAMING_SNAKE_CASE							) % 2 != 0:
												lowercase_     :					Dict													=	F'''Odd number of symbols ({len(__SCREAMING_SNAKE_CASE							)})'''
												raise Exception(__SCREAMING_SNAKE_CASE							)
						elif pbstring == "":
												return {}

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

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

						# Created the dictionary
						lowercase_     :					Dict													=	{}
						for j in range(0				,				len(__SCREAMING_SNAKE_CASE							) - 1				,				2							):
												lowercase_     :					str													=	pbstring[j + 1]
												lowercase_     :					Optional[Any]													=	pbstring[j]

						return pb
def  snake_case_		(    __SCREAMING_SNAKE_CASE :			str				,				__SCREAMING_SNAKE_CASE :			RotorPositionT				,				__SCREAMING_SNAKE_CASE :			RotorSelectionT = (rotora, rotora, rotora)				,				__SCREAMING_SNAKE_CASE :			str = ""				,				):



						"""simple docstring"""





						lowercase_     :					Optional[int]													=	text.upper()
						lowercase_						,			lowercase_						,			lowercase_     :					int													=	_validator(
						    __SCREAMING_SNAKE_CASE				,				__SCREAMING_SNAKE_CASE				,				plugb.upper()							)

						lowercase_						,			lowercase_						,			lowercase_     :					Tuple													=	rotor_position
						lowercase_						,			lowercase_						,			lowercase_     :					str													=	rotor_selection
						rotorposa -= 1
						rotorposa -= 1
						rotorposa -= 1

						lowercase_     :					Tuple													=	[]

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

																		# rotor ra --------------------------
																		lowercase_     :					str													=	abc.index(__SCREAMING_SNAKE_CASE							) + rotorposa
																		lowercase_     :					str													=	rotora[index % len(__SCREAMING_SNAKE_CASE							)]

																		# rotor rb --------------------------
																		lowercase_     :					Any													=	abc.index(__SCREAMING_SNAKE_CASE							) + rotorposa
																		lowercase_     :					Optional[int]													=	rotora[index % len(__SCREAMING_SNAKE_CASE							)]

																		# rotor rc --------------------------
																		lowercase_     :					str													=	abc.index(__SCREAMING_SNAKE_CASE							) + rotorposa
																		lowercase_     :					Any													=	rotora[index % len(__SCREAMING_SNAKE_CASE							)]

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

																		lowercase_     :					Optional[Any]													=	reflector[symbol]

																		# 2nd rotors
																		lowercase_     :					List[str]													=	abc[rotora.index(__SCREAMING_SNAKE_CASE							) - rotorposa]
																		lowercase_     :					Dict													=	abc[rotora.index(__SCREAMING_SNAKE_CASE							) - rotorposa]
																		lowercase_     :					Optional[int]													=	abc[rotora.index(__SCREAMING_SNAKE_CASE							) - rotorposa]

																		# 2nd plugboard
																		if symbol in plugboard:
																								lowercase_     :					str													=	plugboard[symbol]

																		# moves/resets rotor positions
																		rotorposa += 1
																		if rotorposa >= len(__SCREAMING_SNAKE_CASE							):
																								lowercase_     :					Dict													=	0
																								rotorposa += 1
																		if rotorposa >= len(__SCREAMING_SNAKE_CASE							):
																								lowercase_     :					str													=	0
																								rotorposa += 1
																		if rotorposa >= len(__SCREAMING_SNAKE_CASE							):
																								lowercase_     :					int													=	0

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

						return "".join(__SCREAMING_SNAKE_CASE							)


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

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





'''simple docstring'''







from __future__ import annotations

from typing import Any






class 			lowerCAmelCase__       :






					def __init__(       self    ,							__SCREAMING_SNAKE_CASE		):


											"""simple docstring"""





											lowercase_     :					str													=	num_of_nodes
											lowercase_     :					list[list[int]]													=	[]
											lowercase_     :					dict[int, int]													=	{}






					def      _snake_case   (       self    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE		):


											"""simple docstring"""





											self.m_edges.append([u_node, v_node, weight]		)






					def      _snake_case   (       self    ,							__SCREAMING_SNAKE_CASE		):


											"""simple docstring"""





											if self.m_component[u_node] == u_node:
																	return u_node
											return self.find_component(self.m_component[u_node]		)






					def      _snake_case   (       self    ,							__SCREAMING_SNAKE_CASE		):


											"""simple docstring"""





											if self.m_component[u_node] != u_node:
																	for k in self.m_component:
																							lowercase_     :					Optional[int]													=	self.find_component(__SCREAMING_SNAKE_CASE		)






					def      _snake_case   (       self    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE		):


											"""simple docstring"""





											if component_size[u_node] <= component_size[v_node]:
																	lowercase_     :					Any													=	v_node
																	component_size[v_node] += component_size[u_node]
																	self.set_component(__SCREAMING_SNAKE_CASE		)

											elif component_size[u_node] >= component_size[v_node]:
																	lowercase_     :					int													=	self.find_component(__SCREAMING_SNAKE_CASE		)
																	component_size[u_node] += component_size[v_node]
																	self.set_component(__SCREAMING_SNAKE_CASE		)






					def      _snake_case   (       self		):


											"""simple docstring"""





											lowercase_     :					Dict													=	[]
											lowercase_     :					Optional[Any]													=	0

											lowercase_     :					list[Any]													=	[-1] * self.m_num_of_nodes

											# A list of components (initialized to all of the nodes)
											for node in range(self.m_num_of_nodes		):
																	self.m_component.update({node: node}		)
																	component_size.append(1		)

											lowercase_     :					Union[str, Any]													=	self.m_num_of_nodes

											while num_of_components > 1:
																	for edge in self.m_edges:
																							lowercase_						,			lowercase_						,			lowercase_     :					List[Any]													=	edge

																							lowercase_     :					Dict													=	self.m_component[u]
																							lowercase_     :					Any													=	self.m_component[v]

																							if u_component != v_component:

																													for component in (u_component, v_component):
																																			if (
																																			    minimum_weight_edge[component] == -1
																																			    or minimum_weight_edge[component][2] > w
																																			):
																																									lowercase_     :					Union[str, Any]													=	[u, v, w]

																	for edge in minimum_weight_edge:
																							if isinstance(__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE		):
																													lowercase_						,			lowercase_						,			lowercase_     :					str													=	edge

																													lowercase_     :					Tuple													=	self.m_component[u]
																													lowercase_     :					Union[str, Any]													=	self.m_component[v]

																													if u_component != v_component:
																																			mst_weight += w
																																			self.union(__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE		)
																																			print(F'''Added edge [{u} - {v}]\nAdded weight: {w}\n'''		)
																																			num_of_components -= 1

																	lowercase_     :					str													=	[-1] * self.m_num_of_nodes
											print(F'''The total weight of the minimal spanning tree is: {mst_weight}'''		)







def  snake_case_		(    ):



						"""simple docstring"""







if __name__ == "__main__":
							import doctest

							doctest.testmod()



