

"""simple docstring"""





from __future__ import annotations

__UpperCamelCase  :      Union[str, Any]							      =		tuple[int, int, int]
__UpperCamelCase  :      str							      =		tuple[str, str, str]


# used alphabet --------------------------
# from string.ascii_uppercase
__UpperCamelCase  :      List[str]							      =		'''ABCDEFGHIJKLMNOPQRSTUVWXYZ'''

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

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

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

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

	# Validates string and returns dict
	lowerCAmelCase__	:						List[Any]  				=	_plugboard(A_ )

	return rotpos, rotsel, pbdict

def   __SCREAMING_SNAKE_CASE  (      A_ ):

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

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

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

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

	return pb

def   __SCREAMING_SNAKE_CASE  (      A_						,     A_						,     A_ = (rotora, rotora, rotora)						,     A_ = ""						,     ):
	lowerCAmelCase__	:						List[str]  				=	text.upper()
	lowerCAmelCase__				,lowerCAmelCase__				,lowerCAmelCase__	:						str  				=	_validator(
	    A_						,     A_						,     plugb.upper() )

	lowerCAmelCase__				,lowerCAmelCase__				,lowerCAmelCase__	:						List[str]  				=	rotor_position
	lowerCAmelCase__				,lowerCAmelCase__				,lowerCAmelCase__	:						Union[str, Any]  				=	rotor_selection
	rotorposa -= 1
	rotorposa -= 1
	rotorposa -= 1

	lowerCAmelCase__	:						Optional[int]  				=	[]

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

			# rotor ra --------------------------
			lowerCAmelCase__	:						Any  				=	abc.index(A_ ) + rotorposa
			lowerCAmelCase__	:						Optional[int]  				=	rotora[index % len(A_ )]

			# rotor rb --------------------------
			lowerCAmelCase__	:						Any  				=	abc.index(A_ ) + rotorposa
			lowerCAmelCase__	:						List[str]  				=	rotora[index % len(A_ )]

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

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

			lowerCAmelCase__	:						List[str]  				=	reflector[symbol]

			# 2nd rotors
			lowerCAmelCase__	:						Any  				=	abc[rotora.index(A_ ) - rotorposa]
			lowerCAmelCase__	:						str  				=	abc[rotora.index(A_ ) - rotorposa]
			lowerCAmelCase__	:						Tuple  				=	abc[rotora.index(A_ ) - rotorposa]

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

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

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

	return "".join(A_ )


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

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







"""simple docstring"""





def   __SCREAMING_SNAKE_CASE  (      A_						,     A_ ):
	return numa ^ numa < 0


if __name__ == "__main__":
							import doctest

							doctest.testmod()




