






def     _snake_case    (__lowercase    ,      __lowercase				):
   UpperCamelCase_									=     ''
   for i in table:
      res += inp[i - 1]
   return res






def     _snake_case    (__lowercase				):
   return data[1:] + data[0]






def     _snake_case    (__lowercase    ,      __lowercase				):
   UpperCamelCase_									=     ''
   for i in range(len(__lowercase				)				):
      if a[i] == b[i]:
         res += "0"
      else:
         res += "1"
   return res






def     _snake_case    (__lowercase    ,      __lowercase				):
   UpperCamelCase_									=     int('0b' + data[0] + data[-1]    ,      2				)
   UpperCamelCase_									=     int('0b' + data[1:3]    ,      2				)
   return bin(s[row][col]				)[2:]






def     _snake_case    (__lowercase    ,      __lowercase    ,      __lowercase    ,      __lowercase    ,      __lowercase				):
   UpperCamelCase_									=     message[:4]
   UpperCamelCase_									=     message[4:]
   UpperCamelCase_									=     apply_table(__lowercase    ,      __lowercase				)
   UpperCamelCase_									=     xor(__lowercase    ,      __lowercase				)
   UpperCamelCase_									=     apply_sbox(__lowercase    ,      temp[:4]				)  # noqa: E741
   UpperCamelCase_									=     apply_sbox(__lowercase    ,      temp[4:]				)
   UpperCamelCase_									=     '0' * (2 - len(__lowercase				)) + l  # noqa: E741
   UpperCamelCase_									=     '0' * (2 - len(__lowercase				)) + r
   UpperCamelCase_									=     apply_table(l + r    ,      __lowercase				)
   UpperCamelCase_									=     xor(__lowercase    ,      __lowercase				)
   return temp + right


if __name__ == "__main__":
 snake_case__      :	Any       	=      input("""Enter 10 bit key: """)
 snake_case__      :	Dict       	=      input("""Enter 8 bit message: """)

 snake_case__      :	List[Any]       	=      [6, 3, 7, 4, 8, 5, 1_0, 9]
 snake_case__      :	Dict       	=      [3, 5, 2, 7, 4, 1_0, 1, 9, 8, 6]
 snake_case__      :	int       	=      [2, 4, 3, 1]
 snake_case__      :	Any       	=      [2, 6, 3, 1, 4, 8, 5, 7]
 snake_case__      :	Tuple       	=      [4, 1, 3, 5, 7, 2, 8, 6]
 snake_case__      :	int       	=      [4, 1, 2, 3, 2, 3, 4, 1]
 snake_case__      :	Any       	=      [[1, 0, 3, 2], [3, 2, 1, 0], [0, 2, 1, 3], [3, 1, 3, 2]]
 snake_case__      :	str       	=      [[0, 1, 2, 3], [2, 0, 1, 3], [3, 0, 1, 0], [2, 1, 0, 3]]

 # key generation
 snake_case__      :	str       	=      apply_table(key, paa_table)
 snake_case__      :	List[str]       	=      temp[:5]
 snake_case__      :	Any       	=      temp[5:]
 snake_case__      :	List[Any]       	=      left_shift(left)
 snake_case__      :	Optional[int]       	=      left_shift(right)
 snake_case__      :	Dict       	=      apply_table(left + right, pa_table)
 snake_case__      :	Any       	=      left_shift(left)
 snake_case__      :	Tuple       	=      left_shift(right)
 snake_case__      :	int       	=      left_shift(left)
 snake_case__      :	str       	=      left_shift(right)
 snake_case__      :	Optional[Any]       	=      apply_table(left + right, pa_table)

 # encryption
 snake_case__      :	int       	=      apply_table(message, IP)
 snake_case__      :	Tuple       	=      function(expansion, sa, sa, keya, temp)
 snake_case__      :	int       	=      temp[4:] + temp[:4]
 snake_case__      :	Optional[int]       	=      function(expansion, sa, sa, keya, temp)
 snake_case__      :	str       	=      apply_table(temp, IP_inv)
 print("""Cipher text is:""", CT)

 # decryption
 snake_case__      :	Optional[Any]       	=      apply_table(CT, IP)
 snake_case__      :	Optional[int]       	=      function(expansion, sa, sa, keya, temp)
 snake_case__      :	Union[str, Any]       	=      temp[4:] + temp[:4]
 snake_case__      :	Optional[Any]       	=      function(expansion, sa, sa, keya, temp)
 snake_case__      :	Union[str, Any]       	=      apply_table(temp, IP_inv)
 print("""Plain text after decypting is:""", PT)













from typing import Any






def     _snake_case    (__lowercase    ,      __lowercase    ,      __lowercase    ,      __lowercase    ,      __lowercase    ,      ):
   _validation(
       __lowercase    ,      __lowercase    ,      __lowercase    ,      __lowercase    ,      __lowercase    ,      )
   # Creates data structures and fill initial step
   UpperCamelCase_									=     {}
   UpperCamelCase_									=     {}
   for state in states_space:
      UpperCamelCase_									=     observations_space[0]
      UpperCamelCase_									=     (
          initial_probabilities[state] * emission_probabilities[state][observation]
      )
      UpperCamelCase_									=     None

   # Fills the data structure with the probabilities of
   # different transitions and pointers to previous states
   for o in range(1    ,      len(__lowercase)):
      UpperCamelCase_									=     observations_space[o]
      UpperCamelCase_									=     observations_space[o - 1]
      for state in states_space:
         # Calculates the argmax for probability function
         UpperCamelCase_									=     ''
         UpperCamelCase_									=     -1
         for k_state in states_space:
            UpperCamelCase_									=     (
                probabilities[(k_state, prior_observation)]
                * transition_probabilities[k_state][state]
                * emission_probabilities[state][observation]
            )
            if probability > max_probability:
               UpperCamelCase_									=     probability
               UpperCamelCase_									=     k_state

            # Update probabilities and pointers dicts
         UpperCamelCase_									=     (
             probabilities[(arg_max, prior_observation)]
             * transition_probabilities[arg_max][state]
             * emission_probabilities[state][observation]
         )

         UpperCamelCase_									=     arg_max

    # The final observation
   UpperCamelCase_									=     observations_space[len(__lowercase) - 1]

   # argmax for given final observation
   UpperCamelCase_									=     ''
   UpperCamelCase_									=     -1
   for k_state in states_space:
      UpperCamelCase_									=     probabilities[(k_state, final_observation)]
      if probability > max_probability:
         UpperCamelCase_									=     probability
         UpperCamelCase_									=     k_state
   UpperCamelCase_									=     arg_max

   # Process pointers backwards
   UpperCamelCase_									=     last_state
   UpperCamelCase_									=     []
   for o in range(len(__lowercase) - 1    ,      -1    ,      -1):
      result.append(__lowercase)
      UpperCamelCase_									=     pointers[previous, observations_space[o]]
   result.reverse()

   return result






def     _snake_case    (__lowercase    ,      __lowercase    ,      __lowercase    ,      __lowercase    ,      __lowercase    ,      ):
   _validate_not_empty(
       __lowercase    ,      __lowercase    ,      __lowercase    ,      __lowercase    ,      __lowercase    ,      )
   _validate_lists(__lowercase    ,      __lowercase)
   _validate_dicts(
       __lowercase    ,      __lowercase    ,      __lowercase)






def     _snake_case    (__lowercase    ,      __lowercase    ,      __lowercase    ,      __lowercase    ,      __lowercase    ,      ):
   if not all(
       [
           observations_space,
           states_space,
           initial_probabilities,
           transition_probabilities,
           emission_probabilities,
       ]):
      raise ValueError('There\'s an empty parameter')






def     _snake_case    (__lowercase    ,      __lowercase):
   _validate_list(__lowercase    ,      'observations_space')
   _validate_list(__lowercase    ,      'states_space')






def     _snake_case    (__lowercase    ,      __lowercase):
   if not isinstance(_object    ,      __lowercase):
      UpperCamelCase_									=     f"""{var_name} must be a list"""
      raise ValueError(__lowercase)
   else:
      for x in _object:
         if not isinstance(__lowercase    ,      __lowercase):
            UpperCamelCase_									=     f"""{var_name} must be a list of strings"""
            raise ValueError(__lowercase)






def     _snake_case    (__lowercase    ,      __lowercase    ,      __lowercase    ,      ):
   _validate_dict(__lowercase    ,      'initial_probabilities'    ,      __lowercase)
   _validate_nested_dict(__lowercase    ,      'transition_probabilities')
   _validate_nested_dict(__lowercase    ,      'emission_probabilities')






def     _snake_case    (__lowercase    ,      __lowercase):
   _validate_dict(_object    ,      __lowercase    ,      __lowercase)
   for x in _object.values():
      _validate_dict(__lowercase    ,      __lowercase    ,      __lowercase    ,      __lowercase)






def     _snake_case    (__lowercase    ,      __lowercase    ,      __lowercase    ,      __lowercase = False):
   if not isinstance(_object    ,      __lowercase):
      UpperCamelCase_									=     f"""{var_name} must be a dict"""
      raise ValueError(__lowercase)
   if not all(isinstance(__lowercase    ,      __lowercase) for x in _object):
      UpperCamelCase_									=     f"""{var_name} all keys must be strings"""
      raise ValueError(__lowercase)
   if not all(isinstance(__lowercase    ,      __lowercase) for x in _object.values()):
      UpperCamelCase_									=     'nested dictionary ' if nested else ''
      UpperCamelCase_									=     f"""{var_name} {nested_text}all values must be {value_type.__name__}"""
      raise ValueError(__lowercase)


if __name__ == "__main__":
 from doctest import testmod

 testmod()





