


"""simple docstring"""






from __future__ import annotations

_lowerCamelCase     =			tuple[int, int, int]
_lowerCamelCase     =			tuple[str, str, str]


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

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


def __lowercase     (      lowerCamelCase_  :      Optional[Any]						,					lowerCamelCase_  :      Optional[int]						,					lowerCamelCase_  :      List[str]  ):

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

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

				# Validates string and returns dict
				SCREAMING_SNAKE_CASE__     							=				_plugboard(lowerCamelCase_  )

				return rotpos, rotsel, pbdict


def __lowercase     (      lowerCamelCase_  :      Dict  ):

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

				pbstring.replace(" "						,					""  )

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

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

				return pb


def __lowercase     (      lowerCamelCase_  :      Dict						,					lowerCamelCase_  :      Tuple						,					lowerCamelCase_  :      Dict = (rotora, rotora, rotora)						,					lowerCamelCase_  :      List[str] = ""						,					):
				SCREAMING_SNAKE_CASE__     							=				text.upper()
				SCREAMING_SNAKE_CASE__							,      SCREAMING_SNAKE_CASE__							,      SCREAMING_SNAKE_CASE__     							=				_validator(
				    lowerCamelCase_						,					lowerCamelCase_						,					plugb.upper()  )

				SCREAMING_SNAKE_CASE__							,      SCREAMING_SNAKE_CASE__							,      SCREAMING_SNAKE_CASE__     							=				rotor_position
				SCREAMING_SNAKE_CASE__							,      SCREAMING_SNAKE_CASE__							,      SCREAMING_SNAKE_CASE__     							=				rotor_selection
				rotorposa -= 1
				rotorposa -= 1
				rotorposa -= 1

				SCREAMING_SNAKE_CASE__     							=				[]

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

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

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

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

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

												SCREAMING_SNAKE_CASE__     							=				reflector[symbol]

												# 2nd rotors
												SCREAMING_SNAKE_CASE__     							=				abc[rotora.index(lowerCamelCase_  ) - rotorposa]
												SCREAMING_SNAKE_CASE__     							=				abc[rotora.index(lowerCamelCase_  ) - rotorposa]
												SCREAMING_SNAKE_CASE__     							=				abc[rotora.index(lowerCamelCase_  ) - rotorposa]

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

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

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

				return "".join(lowerCamelCase_  )


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

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




"""simple docstring"""






from maths.is_square_free import is_square_free
from maths.prime_factors import prime_factors


def __lowercase     (      lowerCamelCase_  :      int  ):
				SCREAMING_SNAKE_CASE__     							=				prime_factors(lowerCamelCase_  )
				if is_square_free(lowerCamelCase_  ):
								return -1 if len(lowerCamelCase_  ) % 2 else 1
				return 0


if __name__ == "__main__":
	import doctest

	doctest.testmod()
