



# Copyright 2023 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


__snake_case		:str   	=  {
    '''configuration_xmod''': [
        '''XMOD_PRETRAINED_CONFIG_ARCHIVE_MAP''',
        '''XmodConfig''',
        '''XmodOnnxConfig''',
    ],
}

try:
 if not is_torch_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 __snake_case		:Union[str, Any]   	=  [
     '''XMOD_PRETRAINED_MODEL_ARCHIVE_LIST''',
     '''XmodForCausalLM''',
     '''XmodForMaskedLM''',
     '''XmodForMultipleChoice''',
     '''XmodForQuestionAnswering''',
     '''XmodForSequenceClassification''',
     '''XmodForTokenClassification''',
     '''XmodModel''',
     '''XmodPreTrainedModel''',
 ]

if TYPE_CHECKING:
 from .configuration_xmod import XMOD_PRETRAINED_CONFIG_ARCHIVE_MAP, XmodConfig, XmodOnnxConfig

 try:
  if not is_torch_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_xmod import (
      XMOD_PRETRAINED_MODEL_ARCHIVE_LIST,
      XmodForCausalLM,
      XmodForMaskedLM,
      XmodForMultipleChoice,
      XmodForQuestionAnswering,
      XmodForSequenceClassification,
      XmodForTokenClassification,
      XmodModel,
      XmodPreTrainedModel,
  )

else:
 import sys

 __snake_case		:Tuple   	=  _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)










def   __snake_case			(    _UpperCAmelCase       ):
    __a		 =       ''''''
    for ch in key:
        if ch == " " or ch not in key_no_dups and ch.isalpha():
            key_no_dups += ch
    return key_no_dups





def   __snake_case			(    _UpperCAmelCase       ):
    __a		 =       [chr(i + 65       ) for i in range(26       )]
    # Remove duplicate characters from key
    __a		 =       remove_duplicates(key.upper()       )
    __a		 =       len(_UpperCAmelCase       )
    # First fill cipher with key characters
    __a		 =       {alphabet[i]: char for i, char in enumerate(_UpperCAmelCase       )}
    # Then map remaining characters in alphabet to
    # the alphabet from the beginning
    for i in range(len(_UpperCAmelCase       )     ,				26       ):
        __a		 =       alphabet[i - offset]
        # Ensure we are not mapping letters to letters previously mapped
        while char in key:
            offset -= 1
            __a		 =       alphabet[i - offset]
        __a		 =       char
    return cipher_alphabet





def   __snake_case			(    _UpperCAmelCase     ,				_UpperCAmelCase       ):
    return "".join(cipher_map.get(_UpperCAmelCase     ,				_UpperCAmelCase       ) for ch in message.upper()       )





def   __snake_case			(    _UpperCAmelCase     ,				_UpperCAmelCase       ):
    __a		 =       {v: k for k, v in cipher_map.items()}
    return "".join(rev_cipher_map.get(_UpperCAmelCase     ,				_UpperCAmelCase       ) for ch in message.upper()       )





def   __snake_case			(    ):
    __a		 =       input('''Enter message to encode or decode: '''       ).strip()
    __a		 =       input('''Enter keyword: '''       ).strip()
    __a		 =       input('''Encipher or decipher? E/D:'''       ).strip()[0].lower()
    try:
        __a		 =       {'''e''': encipher, '''d''': decipher}[option]
    except KeyError:
        raise KeyError('''invalid input option'''       )
    __a		 =       create_cipher_map(_UpperCAmelCase       )
    print(func(_UpperCAmelCase     ,				_UpperCAmelCase       )       )


if __name__ == "__main__":
 import doctest

 doctest.testmod()
 main()





