





'''simple docstring'''




def _lowerCAmelCase     (      _lowerCAmelCase       ,    _lowerCAmelCase    )->     str:
 __UpperCAmelCase					=   ''
 for i in table:
  res += inp[i - 1]
 return res







def _lowerCAmelCase     (      _lowerCAmelCase    )->     str:
 return data[1:] + data[0]







def _lowerCAmelCase     (      _lowerCAmelCase       ,    _lowerCAmelCase    )->     Union[str, Any]:
 __UpperCAmelCase					=   ''
 for i in range(len(_lowerCAmelCase    )    ):
  if a[i] == b[i]:
   res += "0"
  else:
   res += "1"
 return res







def _lowerCAmelCase     (      _lowerCAmelCase       ,    _lowerCAmelCase    )->     Optional[int]:
 __UpperCAmelCase					=   int('0b' + data[0] + data[-1]       ,    2    )
 __UpperCAmelCase					=   int('0b' + data[1:3]       ,    2    )
 return bin(s[row][col]    )[2:]







def _lowerCAmelCase     (      _lowerCAmelCase       ,    _lowerCAmelCase       ,    _lowerCAmelCase       ,    _lowerCAmelCase       ,    _lowerCAmelCase    )->     List[Any]:
 __UpperCAmelCase					=   message[:4]
 __UpperCAmelCase					=   message[4:]
 __UpperCAmelCase					=   apply_table(_lowerCAmelCase       ,    _lowerCAmelCase    )
 __UpperCAmelCase					=   xor(_lowerCAmelCase       ,    _lowerCAmelCase    )
 __UpperCAmelCase					=   apply_sbox(_lowerCAmelCase       ,    temp[:4]    )  # noqa: E741
 __UpperCAmelCase					=   apply_sbox(_lowerCAmelCase       ,    temp[4:]    )
 __UpperCAmelCase					=   '0' * (2 - len(_lowerCAmelCase    )) + l  # noqa: E741
 __UpperCAmelCase					=   '0' * (2 - len(_lowerCAmelCase    )) + r
 __UpperCAmelCase					=   apply_table(l + r       ,    _lowerCAmelCase    )
 __UpperCAmelCase					=   xor(_lowerCAmelCase       ,    _lowerCAmelCase    )
 return temp + right


if __name__ == "__main__":
    _A:					Tuple							=				input("""Enter 10 bit key: """)
    _A:					Optional[Any]							=				input("""Enter 8 bit message: """)

    _A:					Union[str, Any]							=				[6, 3, 7, 4, 8, 5, 10, 9]
    _A:					int							=				[3, 5, 2, 7, 4, 10, 1, 9, 8, 6]
    _A:					Optional[Any]							=				[2, 4, 3, 1]
    _A:					str							=				[2, 6, 3, 1, 4, 8, 5, 7]
    _A:					List[Any]							=				[4, 1, 3, 5, 7, 2, 8, 6]
    _A:					Dict							=				[4, 1, 2, 3, 2, 3, 4, 1]
    _A:					List[Any]							=				[[1, 0, 3, 2], [3, 2, 1, 0], [0, 2, 1, 3], [3, 1, 3, 2]]
    _A:					Union[str, Any]							=				[[0, 1, 2, 3], [2, 0, 1, 3], [3, 0, 1, 0], [2, 1, 0, 3]]

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

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

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












'''simple docstring'''




import logging
import random

import ray

from transformers import RagConfig, RagRetriever, RagTokenizer
from transformers.models.rag.retrieval_rag import CustomHFIndex


_A:					int							=				logging.getLogger(__name__)






class UpperCAmelCase							:



    def __init__(  self					):
     __UpperCAmelCase					=   False



    def 					__lowerCamelCase						(  self     ,			__A     ,			__A     ,			__A     ,			__A					):
     if not self.initialized:
      __UpperCAmelCase					=   RagRetriever(
          __A     ,			question_encoder_tokenizer=__A     ,			generator_tokenizer=__A     ,			index=__A     ,			init_retrieval=__A     ,			)
      __UpperCAmelCase					=   True



    def 					__lowerCamelCase						(  self					):
     self.retriever.index.init_index()




    def 					__lowerCamelCase						(  self     ,			__A     ,			__A					):
     __UpperCAmelCase					,    __UpperCAmelCase					=   self.retriever._main_retrieve(__A     ,			__A					)
     return doc_ids, retrieved_doc_embeds






class UpperCAmelCase							(		UpperCAmelCase_							):



    def __init__(  self     ,			__A     ,			__A     ,			__A     ,			__A     ,			__A=None					):
     if index is not None and index.is_initialized() and len(__A					) > 0:
      raise ValueError(
          'When using Ray for distributed fine-tuning, '
          'you\'ll need to provide the paths instead, '
          'as the dataset and the index are loaded '
          'separately. More info in examples/rag/use_own_knowledge_dataset.py '					)
     super().__init__(
         __A     ,			question_encoder_tokenizer=__A     ,			generator_tokenizer=__A     ,			index=__A     ,			init_retrieval=__A     ,			)
     __UpperCAmelCase					=   retrieval_workers
     if len(self.retrieval_workers					) > 0:
      ray.get(
          [
              worker.create_rag_retriever.remote(__A     ,			__A     ,			__A     ,			__A					)
              for worker in self.retrieval_workers
          ]					)



    def 					__lowerCamelCase						(  self					):
     logger.info('initializing retrieval'					)

     if len(self.retrieval_workers					) > 0:
      ray.get([worker.init_retrieval.remote() for worker in self.retrieval_workers]					)
     else:
      # Non-distributed training. Load index into this same process.
      self.index.init_index()



    def 					__lowerCamelCase						(  self     ,			__A     ,			__A					):
     if len(self.retrieval_workers					) > 0:
      # Select a random retrieval actor.
      __UpperCAmelCase					=   self.retrieval_workers[random.randint(0     ,			len(self.retrieval_workers					) - 1					)]
      __UpperCAmelCase					,    __UpperCAmelCase					=   ray.get(random_worker.retrieve.remote(__A     ,			__A					)					)
     else:
      __UpperCAmelCase					,    __UpperCAmelCase					=   self._main_retrieve(__A     ,			__A					)
     return retrieved_doc_embeds, doc_ids, self.index.get_doc_dicts(__A					)



    @classmethod
    def 					__lowerCamelCase						(  cls     ,			__A     ,			__A=None     ,			**__A					):
     return super(__A     ,			cls					).get_tokenizers(__A     ,			__A     ,			**__A					)




    @classmethod
    def 					__lowerCamelCase						(  cls     ,			__A     ,			__A     ,			__A=None     ,			**__A					):
     __UpperCAmelCase					=   kwargs.pop('config'     ,			__A					) or RagConfig.from_pretrained(__A     ,			**__A					)
     __UpperCAmelCase					=   RagTokenizer.from_pretrained(__A     ,			config=__A					)
     __UpperCAmelCase					=   rag_tokenizer.question_encoder
     __UpperCAmelCase					=   rag_tokenizer.generator
     if indexed_dataset is not None:
      __UpperCAmelCase					=   'custom'
      __UpperCAmelCase					=   CustomHFIndex(config.retrieval_vector_size     ,			__A					)
     else:
      __UpperCAmelCase					=   cls._build_index(__A					)
     return cls(
         __A     ,			question_encoder_tokenizer=__A     ,			generator_tokenizer=__A     ,			retrieval_workers=__A     ,			index=__A     ,			)





