



'''simple docstring'''





from argparse import ArgumentParser, Namespace

from ..utils import logging
from . import BaseTransformersCLICommand

def        a_     (							_lowerCAmelCase       )      ->      List[Any]:
  return ConvertCommand(
      args.model_type       ,args.tf_checkpoint       ,args.pytorch_dump_output       ,args.config       ,args.finetuning_task_name       )


_UpperCamelCase											=						'\ntransformers can only be used from the commandline to convert TensorFlow models in PyTorch, In that case, it requires\nTensorFlow to be installed. Please see https://www.tensorflow.org/install/ for installation instructions.\n'






class 					lowerCamelCase_    (				a_     ):
  """simple docstring"""




  @staticmethod
  def 						_lowercase     ( _a      :	Tuple   )					->					Tuple:
    __lowerCamelCase       :       int           = parser.add_parser(
        'convert'			,	help='CLI tool to run convert model from original author checkpoints to Transformers PyTorch checkpoints.'			,	)
    train_parser.add_argument('--model_type'			,	type=_lowerCamelCase			,	required=_lowerCamelCase			,	help='Model\'s type.'   )
    train_parser.add_argument(
        '--tf_checkpoint'			,	type=_lowerCamelCase			,	required=_lowerCamelCase			,	help='TensorFlow checkpoint path or folder.'   )
    train_parser.add_argument(
        '--pytorch_dump_output'			,	type=_lowerCamelCase			,	required=_lowerCamelCase			,	help='Path to the PyTorch saved model output.'   )
    train_parser.add_argument('--config'			,	type=_lowerCamelCase			,	default=''			,	help='Configuration file path or folder.'   )
    train_parser.add_argument(
        '--finetuning_task_name'			,	type=_lowerCamelCase			,	default=_lowerCamelCase			,	help='Optional fine-tuning task name if the TF model was a finetuned model.'			,	)
    train_parser.set_defaults(func=_lowerCamelCase   )




  def __init__( self      :	List[Any]			,	_a      :	Optional[int]			,	_a      :	Union[str, Any]			,	_a      :	Dict			,	_a      :	Optional[int]			,	_a      :	Any			,	*_a      :	Tuple			,	)					->					Tuple:
    __lowerCamelCase       :       Any           = logging.get_logger('transformers-cli/converting'   )

    self._logger.info(f'Loading model {model_type}'   )
    __lowerCamelCase       :       Optional[Any]           = model_type
    __lowerCamelCase       :       List[Any]           = tf_checkpoint
    __lowerCamelCase       :       Optional[int]           = pytorch_dump_output
    __lowerCamelCase       :       Optional[Any]           = config
    __lowerCamelCase       :       Union[str, Any]           = finetuning_task_name




  def 						_lowercase     ( self      :	int   )					->					Union[str, Any]:
    if self._model_type == "albert":
      try:
        from ..models.albert.convert_albert_original_tf_checkpoint_to_pytorch import (
            convert_tf_checkpoint_to_pytorch,
        )
      except ImportError:
        raise ImportError(_lowerCamelCase   )

      convert_tf_checkpoint_to_pytorch(self._tf_checkpoint			,	self._config			,	self._pytorch_dump_output   )
    elif self._model_type == "bert":
      try:
        from ..models.bert.convert_bert_original_tf_checkpoint_to_pytorch import (
            convert_tf_checkpoint_to_pytorch,
        )
      except ImportError:
        raise ImportError(_lowerCamelCase   )

      convert_tf_checkpoint_to_pytorch(self._tf_checkpoint			,	self._config			,	self._pytorch_dump_output   )
    elif self._model_type == "funnel":
      try:
        from ..models.funnel.convert_funnel_original_tf_checkpoint_to_pytorch import (
            convert_tf_checkpoint_to_pytorch,
        )
      except ImportError:
        raise ImportError(_lowerCamelCase   )

      convert_tf_checkpoint_to_pytorch(self._tf_checkpoint			,	self._config			,	self._pytorch_dump_output   )
    elif self._model_type == "t5":
      try:
        from ..models.ta.convert_ta_original_tf_checkpoint_to_pytorch import convert_tf_checkpoint_to_pytorch
      except ImportError:
        raise ImportError(_lowerCamelCase   )

      convert_tf_checkpoint_to_pytorch(self._tf_checkpoint			,	self._config			,	self._pytorch_dump_output   )
    elif self._model_type == "gpt":
      from ..models.openai.convert_openai_original_tf_checkpoint_to_pytorch import (
          convert_openai_checkpoint_to_pytorch,
      )

      convert_openai_checkpoint_to_pytorch(self._tf_checkpoint			,	self._config			,	self._pytorch_dump_output   )
    elif self._model_type == "transfo_xl":
      try:
        from ..models.transfo_xl.convert_transfo_xl_original_tf_checkpoint_to_pytorch import (
            convert_transfo_xl_checkpoint_to_pytorch,
        )
      except ImportError:
        raise ImportError(_lowerCamelCase   )

      if "ckpt" in self._tf_checkpoint.lower():
        __lowerCamelCase       :       Union[str, Any]           = self._tf_checkpoint
        __lowerCamelCase       :       Dict           = ''
      else:
        __lowerCamelCase       :       Any           = self._tf_checkpoint
        __lowerCamelCase       :       List[Any]           = ''
      convert_transfo_xl_checkpoint_to_pytorch(
          _lowerCamelCase			,	self._config			,	self._pytorch_dump_output			,	_lowerCamelCase   )
    elif self._model_type == "gpt2":
      try:
        from ..models.gpta.convert_gpta_original_tf_checkpoint_to_pytorch import (
            convert_gpta_checkpoint_to_pytorch,
        )
      except ImportError:
        raise ImportError(_lowerCamelCase   )

      convert_gpta_checkpoint_to_pytorch(self._tf_checkpoint			,	self._config			,	self._pytorch_dump_output   )
    elif self._model_type == "xlnet":
      try:
        from ..models.xlnet.convert_xlnet_original_tf_checkpoint_to_pytorch import (
            convert_xlnet_checkpoint_to_pytorch,
        )
      except ImportError:
        raise ImportError(_lowerCamelCase   )

      convert_xlnet_checkpoint_to_pytorch(
          self._tf_checkpoint			,	self._config			,	self._pytorch_dump_output			,	self._finetuning_task_name   )
    elif self._model_type == "xlm":
      from ..models.xlm.convert_xlm_original_pytorch_checkpoint_to_pytorch import (
          convert_xlm_checkpoint_to_pytorch,
      )

      convert_xlm_checkpoint_to_pytorch(self._tf_checkpoint			,	self._pytorch_dump_output   )
    elif self._model_type == "lxmert":
      from ..models.lxmert.convert_lxmert_original_tf_checkpoint_to_pytorch import (
          convert_lxmert_checkpoint_to_pytorch,
      )

      convert_lxmert_checkpoint_to_pytorch(self._tf_checkpoint			,	self._pytorch_dump_output   )
    elif self._model_type == "rembert":
      from ..models.rembert.convert_rembert_tf_checkpoint_to_pytorch import (
          convert_rembert_tf_checkpoint_to_pytorch,
      )

      convert_rembert_tf_checkpoint_to_pytorch(self._tf_checkpoint			,	self._config			,	self._pytorch_dump_output   )
    else:
      raise ValueError(
          '--model_type should be selected in the list [bert, gpt, gpt2, t5, transfo_xl, xlnet, xlm, lxmert]'   )














"""simple docstring"""



def 						_SCREAMING_SNAKE_CASE (    __snake_case			:  List[str]		,					__snake_case			:  List[str]    ):





  '''simple docstring'''





  lowercase							    =       ''
  for i in table:
    res += inp[i - 1]
  return res
def 						_SCREAMING_SNAKE_CASE (    __snake_case			:  str    ):





  '''simple docstring'''





  return data[1:] + data[0]
def 						_SCREAMING_SNAKE_CASE (    __snake_case			:  List[str]		,					__snake_case			:  Optional[int]    ):





  '''simple docstring'''





  lowercase							    =       ''
  for i in range(len(__snake_case    )    ):
    if a[i] == b[i]:
      res += "0"
    else:
      res += "1"
  return res
def 						_SCREAMING_SNAKE_CASE (    __snake_case			:  Dict		,					__snake_case			:  Optional[Any]    ):





  '''simple docstring'''





  lowercase							    =       int('0b' + data[0] + data[-1]		,					2    )
  lowercase							    =       int('0b' + data[1:3]		,					2    )
  return bin(s[row][col]    )[2:]
def 						_SCREAMING_SNAKE_CASE (    __snake_case			:  Union[str, Any]		,					__snake_case			:  Union[str, Any]		,					__snake_case			:  Dict		,					__snake_case			:  Union[str, Any]		,					__snake_case			:  Optional[int]    ):





  '''simple docstring'''





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


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

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

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

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

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


