from __future__ import annotations

__lowercase											=      tuple[int, int, int]
__lowercase											=      tuple[str, str, str]


# used alphabet --------------------------
# from string.ascii_uppercase
__lowercase											=      '''ABCDEFGHIJKLMNOPQRSTUVWXYZ'''

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



def lowerCamelCase						(     SCREAMING_SNAKE_CASE						,    SCREAMING_SNAKE_CASE						,    SCREAMING_SNAKE_CASE			):
    '''simple docstring'''







    if (unique_rotsel := len(set(SCREAMING_SNAKE_CASE			)			)) < 3:
        __UpperCamelCase  :List[str]    						=	f"""Please use 3 unique rotors (not {unique_rotsel})"""
        raise Exception(SCREAMING_SNAKE_CASE			)

    # Checks if rotor positions are valid
    __UpperCamelCase						, __UpperCamelCase						, __UpperCamelCase  :Any    						=	rotpos
    if not 0 < rotorposa <= len(SCREAMING_SNAKE_CASE			):
        __UpperCamelCase  :List[Any]    						=	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			):
        __UpperCamelCase  :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			):
        __UpperCamelCase  :str    						=	f"""Third rotor position is not within range of 1..26 ({rotorposa})"""
        raise ValueError(SCREAMING_SNAKE_CASE			)

    # Validates string and returns dict
    __UpperCamelCase  :Any    						=	_plugboard(SCREAMING_SNAKE_CASE			)

    return rotpos, rotsel, pbdict



def lowerCamelCase						(     SCREAMING_SNAKE_CASE			):
    '''simple docstring'''







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

    # Created the dictionary
    __UpperCamelCase  :Optional[int]    						=	{}
    for j in range(0						,    len(SCREAMING_SNAKE_CASE			) - 1						,    2			):
        __UpperCamelCase  :List[Any]    						=	pbstring[j + 1]
        __UpperCamelCase  :Optional[Any]    						=	pbstring[j]

    return pb



def lowerCamelCase						(     SCREAMING_SNAKE_CASE						,    SCREAMING_SNAKE_CASE						,    SCREAMING_SNAKE_CASE = (rotora, rotora, rotora)						,    SCREAMING_SNAKE_CASE = ""						,    ):
    '''simple docstring'''







    __UpperCamelCase  :str    						=	text.upper()
    __UpperCamelCase						, __UpperCamelCase						, __UpperCamelCase  :Dict    						=	_validator(
        SCREAMING_SNAKE_CASE						,    SCREAMING_SNAKE_CASE						,    plugb.upper()			)

    __UpperCamelCase						, __UpperCamelCase						, __UpperCamelCase  :int    						=	rotor_position
    __UpperCamelCase						, __UpperCamelCase						, __UpperCamelCase  :str    						=	rotor_selection
    rotorposa -= 1
    rotorposa -= 1
    rotorposa -= 1

    __UpperCamelCase  :int    						=	[]

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

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

            # rotor rb --------------------------
            __UpperCamelCase  :str    						=	abc.index(SCREAMING_SNAKE_CASE			) + rotorposa
            __UpperCamelCase  :int    						=	rotora[index % len(SCREAMING_SNAKE_CASE			)]

            # rotor rc --------------------------
            __UpperCamelCase  :Optional[Any]    						=	abc.index(SCREAMING_SNAKE_CASE			) + rotorposa
            __UpperCamelCase  :Tuple    						=	rotora[index % len(SCREAMING_SNAKE_CASE			)]

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

            __UpperCamelCase  :Dict    						=	reflector[symbol]

            # 2nd rotors
            __UpperCamelCase  :Optional[Any]    						=	abc[rotora.index(SCREAMING_SNAKE_CASE			) - rotorposa]
            __UpperCamelCase  :str    						=	abc[rotora.index(SCREAMING_SNAKE_CASE			) - rotorposa]
            __UpperCamelCase  :str    						=	abc[rotora.index(SCREAMING_SNAKE_CASE			) - rotorposa]

            # 2nd plugboard
            if symbol in plugboard:
                __UpperCamelCase  :int    						=	plugboard[symbol]

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



def lowerCamelCase						(     SCREAMING_SNAKE_CASE						,    SCREAMING_SNAKE_CASE						,    SCREAMING_SNAKE_CASE = 0						,    SCREAMING_SNAKE_CASE = -1			):
    '''simple docstring'''







    if hi < 0:
        __UpperCamelCase  :str    						=	len(SCREAMING_SNAKE_CASE			)

    while lo < hi:
        __UpperCamelCase  :Optional[int]    						=	lo + (hi - lo) // 2
        if sorted_collection[mid] < item:
            __UpperCamelCase  :List[Any]    						=	mid + 1
        else:
            __UpperCamelCase  :Any    						=	mid

    return lo



def lowerCamelCase						(     SCREAMING_SNAKE_CASE						,    SCREAMING_SNAKE_CASE						,    SCREAMING_SNAKE_CASE = 0						,    SCREAMING_SNAKE_CASE = -1			):
    '''simple docstring'''







    if hi < 0:
        __UpperCamelCase  :List[str]    						=	len(SCREAMING_SNAKE_CASE			)

    while lo < hi:
        __UpperCamelCase  :Optional[Any]    						=	lo + (hi - lo) // 2
        if sorted_collection[mid] <= item:
            __UpperCamelCase  :Dict    						=	mid + 1
        else:
            __UpperCamelCase  :Optional[Any]    						=	mid

    return lo



def lowerCamelCase						(     SCREAMING_SNAKE_CASE						,    SCREAMING_SNAKE_CASE						,    SCREAMING_SNAKE_CASE = 0						,    SCREAMING_SNAKE_CASE = -1			):
    '''simple docstring'''







    sorted_collection.insert(bisect_left(SCREAMING_SNAKE_CASE						,    SCREAMING_SNAKE_CASE						,    SCREAMING_SNAKE_CASE						,    SCREAMING_SNAKE_CASE			)						,    SCREAMING_SNAKE_CASE			)



def lowerCamelCase						(     SCREAMING_SNAKE_CASE						,    SCREAMING_SNAKE_CASE						,    SCREAMING_SNAKE_CASE = 0						,    SCREAMING_SNAKE_CASE = -1			):
    '''simple docstring'''







    sorted_collection.insert(bisect_right(SCREAMING_SNAKE_CASE						,    SCREAMING_SNAKE_CASE						,    SCREAMING_SNAKE_CASE						,    SCREAMING_SNAKE_CASE			)						,    SCREAMING_SNAKE_CASE			)



def lowerCamelCase						(     SCREAMING_SNAKE_CASE						,    SCREAMING_SNAKE_CASE			):
    '''simple docstring'''







    __UpperCamelCase  :Tuple    						=	0
    __UpperCamelCase  :List[str]    						=	len(SCREAMING_SNAKE_CASE			) - 1

    while left <= right:
        __UpperCamelCase  :Optional[int]    						=	left + (right - left) // 2
        __UpperCamelCase  :List[str]    						=	sorted_collection[midpoint]
        if current_item == item:
            return midpoint
        elif item < current_item:
            __UpperCamelCase  :Union[str, Any]    						=	midpoint - 1
        else:
            __UpperCamelCase  :Dict    						=	midpoint + 1
    return None



def lowerCamelCase						(     SCREAMING_SNAKE_CASE						,    SCREAMING_SNAKE_CASE			):
    '''simple docstring'''







    __UpperCamelCase  :Dict    						=	bisect.bisect_left(SCREAMING_SNAKE_CASE						,    SCREAMING_SNAKE_CASE			)
    if index != len(SCREAMING_SNAKE_CASE			) and sorted_collection[index] == item:
        return index
    return None



def lowerCamelCase						(     SCREAMING_SNAKE_CASE						,    SCREAMING_SNAKE_CASE						,    SCREAMING_SNAKE_CASE						,    SCREAMING_SNAKE_CASE			):
    '''simple docstring'''







    if right < left:
        return None

    __UpperCamelCase  :str    						=	left + (right - left) // 2

    if sorted_collection[midpoint] == item:
        return midpoint
    elif sorted_collection[midpoint] > item:
        return binary_search_by_recursion(SCREAMING_SNAKE_CASE						,    SCREAMING_SNAKE_CASE						,    SCREAMING_SNAKE_CASE						,    midpoint - 1			)
    else:
        return binary_search_by_recursion(SCREAMING_SNAKE_CASE						,    SCREAMING_SNAKE_CASE						,    midpoint + 1						,    SCREAMING_SNAKE_CASE			)


if __name__ == "__main__":
    __lowercase											=      input('''Enter numbers separated by comma:\n''').strip()
    __lowercase											=      sorted(int(item) for item in user_input.split(''','''))
    __lowercase											=      int(input('''Enter a single number to be found in the list:\n'''))
    __lowercase											=      binary_search(collection, target)
    if result is None:
        print(F'{target} was not found in {collection}.')
    else:
        print(F'{target} was found at position {result} in {collection}.')





