




'''simple docstring'''







def 						_A      ( UpperCAmelCase      ,UpperCAmelCase						):






   '''simple docstring'''







   A__       =     ''
   for i in table:
      res += inp[i - 1]
   return res







def 						_A      ( UpperCAmelCase						):






   '''simple docstring'''







   return data[1:] + data[0]







def 						_A      ( UpperCAmelCase      ,UpperCAmelCase						):






   '''simple docstring'''







   A__       =     ''
   for i in range(len(UpperCAmelCase						)						):
      if a[i] == b[i]:
         res += "0"
      else:
         res += "1"
   return res







def 						_A      ( UpperCAmelCase      ,UpperCAmelCase						):






   '''simple docstring'''







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







def 						_A      ( UpperCAmelCase      ,UpperCAmelCase      ,UpperCAmelCase      ,UpperCAmelCase      ,UpperCAmelCase						):






   '''simple docstring'''







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


if __name__ == "__main__":
    lowerCAmelCase_     						=				input('''Enter 10 bit key: ''')
    lowerCAmelCase_     						=				input('''Enter 8 bit message: ''')

    lowerCAmelCase_     						=				[6, 3, 7, 4, 8, 5, 1_0, 9]
    lowerCAmelCase_     						=				[3, 5, 2, 7, 4, 1_0, 1, 9, 8, 6]
    lowerCAmelCase_     						=				[2, 4, 3, 1]
    lowerCAmelCase_     						=				[2, 6, 3, 1, 4, 8, 5, 7]
    lowerCAmelCase_     						=				[4, 1, 3, 5, 7, 2, 8, 6]
    lowerCAmelCase_     						=				[4, 1, 2, 3, 2, 3, 4, 1]
    lowerCAmelCase_     						=				[[1, 0, 3, 2], [3, 2, 1, 0], [0, 2, 1, 3], [3, 1, 3, 2]]
    lowerCAmelCase_     						=				[[0, 1, 2, 3], [2, 0, 1, 3], [3, 0, 1, 0], [2, 1, 0, 3]]

    # key generation
    lowerCAmelCase_     						=				apply_table(key, paa_table)
    lowerCAmelCase_     						=				temp[:5]
    lowerCAmelCase_     						=				temp[5:]
    lowerCAmelCase_     						=				left_shift(left)
    lowerCAmelCase_     						=				left_shift(right)
    lowerCAmelCase_     						=				apply_table(left + right, pa_table)
    lowerCAmelCase_     						=				left_shift(left)
    lowerCAmelCase_     						=				left_shift(right)
    lowerCAmelCase_     						=				left_shift(left)
    lowerCAmelCase_     						=				left_shift(right)
    lowerCAmelCase_     						=				apply_table(left + right, pa_table)

    # encryption
    lowerCAmelCase_     						=				apply_table(message, IP)
    lowerCAmelCase_     						=				function(expansion, sa, sa, keya, temp)
    lowerCAmelCase_     						=				temp[4:] + temp[:4]
    lowerCAmelCase_     						=				function(expansion, sa, sa, keya, temp)
    lowerCAmelCase_     						=				apply_table(temp, IP_inv)
    print('''Cipher text is:''', CT)

    # decryption
    lowerCAmelCase_     						=				apply_table(CT, IP)
    lowerCAmelCase_     						=				function(expansion, sa, sa, keya, temp)
    lowerCAmelCase_     						=				temp[4:] + temp[:4]
    lowerCAmelCase_     						=				function(expansion, sa, sa, keya, temp)
    lowerCAmelCase_     						=				apply_table(temp, IP_inv)
    print('''Plain text after decypting is:''', PT)








'''simple docstring'''







import argparse
import copy







def 						_A      ( UpperCAmelCase						):






   '''simple docstring'''







   A__       =     {}

   with open(UpperCAmelCase						) as f:
      for line in f:
         if line.split()[0] not in dict_of_neighbours:
            A__       =     []
            _list.append([line.split()[1], line.split()[2]]						)
            A__       =     _list
         else:
            dict_of_neighbours[line.split()[0]].append(
                [line.split()[1], line.split()[2]]						)
         if line.split()[1] not in dict_of_neighbours:
            A__       =     []
            _list.append([line.split()[0], line.split()[2]]						)
            A__       =     _list
         else:
            dict_of_neighbours[line.split()[1]].append(
                [line.split()[0], line.split()[2]]						)

   return dict_of_neighbours







def 						_A      ( UpperCAmelCase      ,UpperCAmelCase						):






   '''simple docstring'''







   with open(UpperCAmelCase						) as f:
      A__       =     f.read(1						)
   A__       =     start_node

   A__       =     []

   A__       =     start_node

   A__       =     0
   while visiting not in first_solution:
      A__       =     10000
      for k in dict_of_neighbours[visiting]:
         if int(k[1]						) < int(UpperCAmelCase						) and k[0] not in first_solution:
            A__       =     k[1]
            A__       =     k[0]

      first_solution.append(UpperCAmelCase						)
      A__       =     distance_of_first_solution + int(UpperCAmelCase						)
      A__       =     best_node

   first_solution.append(UpperCAmelCase						)

   A__       =     0
   for k in dict_of_neighbours[first_solution[-2]]:
      if k[0] == start_node:
         break
      position += 1

   A__       =     (
       distance_of_first_solution
       + int(dict_of_neighbours[first_solution[-2]][position][1]						)
       - 10000
   )
   return first_solution, distance_of_first_solution







def 						_A      ( UpperCAmelCase      ,UpperCAmelCase						):






   '''simple docstring'''







   A__       =     []

   for n in solution[1:-1]:
      A__       =     solution.index(UpperCAmelCase						)
      for kn in solution[1:-1]:
         A__       =     solution.index(UpperCAmelCase						)
         if n == kn:
            continue

         A__       =     copy.deepcopy(UpperCAmelCase						)
         A__       =     kn
         A__       =     n

         A__       =     0

         for k in _tmp[:-1]:
            A__       =     _tmp[_tmp.index(UpperCAmelCase						) + 1]
            for i in dict_of_neighbours[k]:
               if i[0] == next_node:
                  A__       =     distance + int(i[1]						)
         _tmp.append(UpperCAmelCase						)

         if _tmp not in neighborhood_of_solution:
            neighborhood_of_solution.append(_tmp						)

   A__       =     len(neighborhood_of_solution[0]						) - 1

   neighborhood_of_solution.sort(key=lambda UpperCAmelCase						: x[index_of_last_item_in_the_list]						)
   return neighborhood_of_solution







def 						_A      ( UpperCAmelCase      ,UpperCAmelCase      ,UpperCAmelCase      ,UpperCAmelCase      ,UpperCAmelCase						):






   '''simple docstring'''







   A__       =     1
   A__       =     first_solution
   A__       =     []
   A__       =     distance_of_first_solution
   A__       =     solution

   while count <= iters:
      A__       =     find_neighborhood(UpperCAmelCase      ,UpperCAmelCase						)
      A__       =     0
      A__       =     neighborhood[index_of_best_solution]
      A__       =     len(UpperCAmelCase						) - 1

      A__       =     False
      while not found:
         A__       =     0
         while i < len(UpperCAmelCase						):
            if best_solution[i] != solution[i]:
               A__       =     best_solution[i]
               A__       =     solution[i]
               break
            A__       =     i + 1

         if [first_exchange_node, second_exchange_node] not in tabu_list and [
             second_exchange_node,
             first_exchange_node,
         ] not in tabu_list:
            tabu_list.append([first_exchange_node, second_exchange_node]						)
            A__       =     True
            A__       =     best_solution[:-1]
            A__       =     neighborhood[index_of_best_solution][best_cost_index]
            if cost < best_cost:
               A__       =     cost
               A__       =     solution
         else:
            A__       =     index_of_best_solution + 1
            A__       =     neighborhood[index_of_best_solution]

      if len(UpperCAmelCase						) >= size:
         tabu_list.pop(0						)

      A__       =     count + 1

   return best_solution_ever, best_cost







def 						_A      ( UpperCAmelCase=None						):






   '''simple docstring'''







   A__       =     generate_neighbours(args.File						)

   A__  ,			A__       =     generate_first_solution(
       args.File      ,UpperCAmelCase						)

   A__  ,			A__       =     tabu_search(
       UpperCAmelCase      ,UpperCAmelCase      ,UpperCAmelCase      ,args.Iterations      ,args.Size      ,)

   print(F"""Best solution: {best_sol}, with total distance: {best_cost}."""						)


if __name__ == "__main__":
    lowerCAmelCase_     						=				argparse.ArgumentParser(description='''Tabu Search''')
    parser.add_argument(
        '''-f''',
        '''--File''',
        type=str,
        help='''Path to the file containing the data''',
        required=True,
    )
    parser.add_argument(
        '''-i''',
        '''--Iterations''',
        type=int,
        help='''How many iterations the algorithm should perform''',
        required=True,
    )
    parser.add_argument(
        '''-s''', '''--Size''', type=int, help='''Size of the tabu list''', required=True
    )

    # Pass the arguments to main method
    main(parser.parse_args())


