





from __future__ import annotations

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


# used alphabet --------------------------
# from string.ascii_uppercase
_lowerCamelCase :    Optional[Any]  							= '''ABCDEFGHIJKLMNOPQRSTUVWXYZ'''

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




def _a (  SCREAMING_SNAKE_CASE__      :  RotorPositionT			,				SCREAMING_SNAKE_CASE__      :  RotorSelectionT			,				SCREAMING_SNAKE_CASE__      :  str       )	->    tuple[RotorPositionT, RotorSelectionT, dict[str, str]]:

							'''simple docstring'''






							if (unique_rotsel := len(set(SCREAMING_SNAKE_CASE__       )       )) < 3:
														SCREAMING_SNAKE_CASE__       :      Union[str, Any]     =						f'''Please use 3 unique rotors (not {unique_rotsel})'''
														raise Exception(SCREAMING_SNAKE_CASE__       )

							# Checks if rotor positions are valid
							SCREAMING_SNAKE_CASE__   ,SCREAMING_SNAKE_CASE__   ,SCREAMING_SNAKE_CASE__       :      Optional[int]     =						rotpos
							if not 0 < rotorposa <= len(SCREAMING_SNAKE_CASE__       ):
														SCREAMING_SNAKE_CASE__       :      Dict     =						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__       ):
														SCREAMING_SNAKE_CASE__       :      Optional[Any]     =						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__       ):
														SCREAMING_SNAKE_CASE__       :      int     =						f'''Third rotor position is not within range of 1..26 ({rotorposa})'''
														raise ValueError(SCREAMING_SNAKE_CASE__       )

							# Validates string and returns dict
							SCREAMING_SNAKE_CASE__       :      Dict     =						_plugboard(SCREAMING_SNAKE_CASE__       )

							return rotpos, rotsel, pbdict




def _a (  SCREAMING_SNAKE_CASE__      :  str       )	->    dict[str, str]:

							'''simple docstring'''






							if not isinstance(SCREAMING_SNAKE_CASE__			,				SCREAMING_SNAKE_CASE__       ):
														SCREAMING_SNAKE_CASE__       :      Optional[int]     =						f'''Plugboard setting isn\'t type string ({type(SCREAMING_SNAKE_CASE__       )})'''
														raise TypeError(SCREAMING_SNAKE_CASE__       )
							elif len(SCREAMING_SNAKE_CASE__       ) % 2 != 0:
														SCREAMING_SNAKE_CASE__       :      str     =						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
							SCREAMING_SNAKE_CASE__       :      str     =						set()
							for i in pbstring:
														if i not in abc:
																					SCREAMING_SNAKE_CASE__       :      Optional[int]     =						f'''\'{i}\' not in list of symbols'''
																					raise Exception(SCREAMING_SNAKE_CASE__       )
														elif i in tmppbl:
																					SCREAMING_SNAKE_CASE__       :      int     =						f'''Duplicate symbol ({i})'''
																					raise Exception(SCREAMING_SNAKE_CASE__       )
														else:
																					tmppbl.add(SCREAMING_SNAKE_CASE__       )
							del tmppbl

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

							return pb




def _a (  SCREAMING_SNAKE_CASE__      :  str			,				SCREAMING_SNAKE_CASE__      :  RotorPositionT			,				SCREAMING_SNAKE_CASE__      :  RotorSelectionT = (rotora, rotora, rotora)			,				SCREAMING_SNAKE_CASE__      :  str = ""			,				)	->    str:

							'''simple docstring'''






							SCREAMING_SNAKE_CASE__       :      List[str]     =						text.upper()
							SCREAMING_SNAKE_CASE__   ,SCREAMING_SNAKE_CASE__   ,SCREAMING_SNAKE_CASE__       :      Any     =						_validator(
							    SCREAMING_SNAKE_CASE__			,				SCREAMING_SNAKE_CASE__			,				plugb.upper()       )

							SCREAMING_SNAKE_CASE__   ,SCREAMING_SNAKE_CASE__   ,SCREAMING_SNAKE_CASE__       :      List[Any]     =						rotor_position
							SCREAMING_SNAKE_CASE__   ,SCREAMING_SNAKE_CASE__   ,SCREAMING_SNAKE_CASE__       :      Tuple     =						rotor_selection
							rotorposa -= 1
							rotorposa -= 1
							rotorposa -= 1

							SCREAMING_SNAKE_CASE__       :      Optional[int]     =						[]

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

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

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

																					# rotor rc --------------------------
																					SCREAMING_SNAKE_CASE__       :      Tuple     =						abc.index(SCREAMING_SNAKE_CASE__       ) + rotorposa
																					SCREAMING_SNAKE_CASE__       :      List[Any]     =						rotora[index % len(SCREAMING_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__       :      int     =						abc[rotora.index(SCREAMING_SNAKE_CASE__       ) - rotorposa]
																					SCREAMING_SNAKE_CASE__       :      int     =						abc[rotora.index(SCREAMING_SNAKE_CASE__       ) - rotorposa]
																					SCREAMING_SNAKE_CASE__       :      Any     =						abc[rotora.index(SCREAMING_SNAKE_CASE__       ) - rotorposa]

																					# 2nd plugboard
																					if symbol in plugboard:
																												SCREAMING_SNAKE_CASE__       :      Union[str, Any]     =						plugboard[symbol]

																					# moves/resets rotor positions
																					rotorposa += 1
																					if rotorposa >= len(SCREAMING_SNAKE_CASE__       ):
																												SCREAMING_SNAKE_CASE__       :      Optional[Any]     =						0
																												rotorposa += 1
																					if rotorposa >= len(SCREAMING_SNAKE_CASE__       ):
																												SCREAMING_SNAKE_CASE__       :      int     =						0
																												rotorposa += 1
																					if rotorposa >= len(SCREAMING_SNAKE_CASE__       ):
																												SCREAMING_SNAKE_CASE__       :      Dict     =						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__":
		_lowerCamelCase :    str  							= '''This is my Python script that emulates the Enigma machine from WWII.'''
		_lowerCamelCase :    Any  							= (1, 1, 1)
		_lowerCamelCase :    Optional[int]  							= '''pictures'''
		_lowerCamelCase :    Dict  							= (rotora, rotora, rotora)
		_lowerCamelCase :    Optional[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

import math
from collections import Counter
from string import ascii_lowercase




def _a (  SCREAMING_SNAKE_CASE__      :  str       )	->    None:

							'''simple docstring'''






							SCREAMING_SNAKE_CASE__   ,SCREAMING_SNAKE_CASE__       :      Dict     =						analyze_text(SCREAMING_SNAKE_CASE__       )
							SCREAMING_SNAKE_CASE__       :      Tuple     =						list(" " + ascii_lowercase       )
							# what is our total sum of probabilities.
							SCREAMING_SNAKE_CASE__       :      str     =						sum(single_char_strings.values()       )

							# one length string
							SCREAMING_SNAKE_CASE__       :      str     =						0
							# for each alpha we go in our dict and if it is in it we calculate entropy
							for ch in my_alphas:
														if ch in single_char_strings:
																					SCREAMING_SNAKE_CASE__       :      Optional[int]     =						single_char_strings[ch]
																					SCREAMING_SNAKE_CASE__       :      Any     =						my_str / all_sum
																					my_fir_sum += prob * math.loga(SCREAMING_SNAKE_CASE__       )  # entropy formula.

    # print entropy
							print(f'''{round(-1 * my_fir_sum       ):.1f}'''       )

							# two len string
							SCREAMING_SNAKE_CASE__       :      Union[str, Any]     =						sum(two_char_strings.values()       )
							SCREAMING_SNAKE_CASE__       :      int     =						0
							# for each alpha (two in size) calculate entropy.
							for cha in my_alphas:
														for cha in my_alphas:
																					SCREAMING_SNAKE_CASE__       :      List[str]     =						cha + cha
																					if sequence in two_char_strings:
																												SCREAMING_SNAKE_CASE__       :      Optional[Any]     =						two_char_strings[sequence]
																												SCREAMING_SNAKE_CASE__       :      Tuple     =						int(SCREAMING_SNAKE_CASE__       ) / all_sum
																												my_sec_sum += prob * math.loga(SCREAMING_SNAKE_CASE__       )

    # print second entropy
							print(f'''{round(-1 * my_sec_sum       ):.1f}'''       )

							# print the difference between them
							print(f'''{round((-1 * my_sec_sum) - (-1 * my_fir_sum)       ):.1f}'''       )




def _a (  SCREAMING_SNAKE_CASE__      :  str       )	->    tuple[dict, dict]:

							'''simple docstring'''






							SCREAMING_SNAKE_CASE__       :      str     =						Counter()  # type: ignore
							SCREAMING_SNAKE_CASE__       :      Dict     =						Counter()  # type: ignore
							single_char_strings[text[-1]] += 1

							# first case when we have space at start.
							two_char_strings[" " + text[0]] += 1
							for i in range(0			,				len(SCREAMING_SNAKE_CASE__       ) - 1       ):
														single_char_strings[text[i]] += 1
														two_char_strings[text[i : i + 2]] += 1
							return single_char_strings, two_char_strings




def _a (  )	->    str:

							'''simple docstring'''






							import doctest

							doctest.testmod()
							# text = (
							#     "Had repulsive dashwoods suspicion sincerity but advantage now him. Remark "
							#     "easily garret nor nay. Civil those mrs enjoy shy fat merry. You greatest "
							#     "jointure saw horrible. He private he on be imagine suppose. Fertile "
							#     "beloved evident through no service elderly is. Blind there if every no so "
							#     "at. Own neglected you preferred way sincerity delivered his attempted. To "
							#     "of message cottage windows do besides against uncivil.  Delightful "
							#     "unreserved impossible few estimating men favourable see entreaties. She "
							#     "propriety immediate was improving. He or entrance humoured likewise "
							#     "moderate. Much nor game son say feel. Fat make met can must form into "
							#     "gate. Me we offending prevailed discovery. "
							# )

							# calculate_prob(text)


if __name__ == "__main__":
		main()






