





import string

import numpy



def        _a						(    UpperCAmelCase			,  UpperCAmelCase     )				->				str:







   """simple docstring"""
   return b if a == 0 else greatest_common_divisor(b % a			,  SCREAMING_SNAKE_CASE_     )


class    __SCREAMING_SNAKE_CASE			:
       _UpperCAmelCase      :  Dict     =    string.ascii_uppercase + string.digits
       # This cipher takes alphanumerics into account
       # i.e. a total of 36 characters

       # take x and return x % len(key_string)
       _UpperCAmelCase      :  int     =    numpy.vectorize(lambda lowerCAmelCase_					: x % 3_6					)

       _UpperCAmelCase      :  List[str]     =    numpy.vectorize(__snake_case					)







       def __init__(      self     :	Optional[int]		,					A     :	List[str]			)   ->Tuple:
          lowerCamelCase__   :						Optional[Any]					   =							self.modulus(A			)  # mod36 calc's on the encrypt key
          self.check_determinant()  # validate the determinant of the encryption key
          lowerCamelCase__   :						str					   =							encrypt_key.shape[0]







       def 						__lowerCamelCase    (      self     :	Any		,					A     :	str			)   ->Any:
          return self.key_string.index(A			)







       def 						__lowerCamelCase    (      self     :	Any		,					A     :	Dict			)   ->Any:
          return self.key_string[round(A			)]







       def 						__lowerCamelCase    (      self     :	Union[str, Any]			)   ->Union[str, Any]:
          lowerCamelCase__   :						Optional[int]					   =							round(numpy.linalg.det(self.encrypt_key			)			)

          if det < 0:
             lowerCamelCase__   :						Dict					   =							det % len(self.key_string			)

          lowerCamelCase__   :						str					   =							len(self.key_string			)
          if greatest_common_divisor(A		,					len(self.key_string			)			) != 1:
             lowerCamelCase__   :						Union[str, Any]					   =							(
                 F"determinant modular {req_l} of encryption key({det}) "
                 F"is not co prime w.r.t {req_l}.\nTry another key."
             )
             raise ValueError(A			)







       def 						__lowerCamelCase    (      self     :	int		,					A     :	Tuple			)   ->Dict:
          lowerCamelCase__   :						Tuple					   =							[char for char in text.upper() if char in self.key_string]

          lowerCamelCase__   :						Any					   =							chars[-1]
          while len(A			) % self.break_key != 0:
             chars.append(A			)

          return "".join(A			)







       def 						__lowerCamelCase    (      self     :	Optional[int]		,					A     :	str			)   ->Dict:
          lowerCamelCase__   :						Any					   =							self.process_text(text.upper()			)
          lowerCamelCase__   :						Tuple					   =							''

          for i in range(0		,					len(A			) - self.break_key + 1		,					self.break_key			):
             lowerCamelCase__   :						int					   =							text[i : i + self.break_key]
             lowerCamelCase__   :						Optional[int]					   =							[self.replace_letters(A			) for char in batch]
             lowerCamelCase__   :						str					   =							numpy.array([vec]			).T
             lowerCamelCase__   :						str					   =							self.modulus(self.encrypt_key.dot(A			)			).T.tolist()[
                 0
             ]
             lowerCamelCase__   :						Any					   =							''.join(
                 self.replace_digits(A			) for num in batch_encrypted			)
             encrypted += encrypted_batch

          return encrypted







       def 						__lowerCamelCase    (      self     :	Optional[int]			)   ->Tuple:
          lowerCamelCase__   :						List[Any]					   =							round(numpy.linalg.det(self.encrypt_key			)			)

          if det < 0:
             lowerCamelCase__   :						List[str]					   =							det % len(self.key_string			)
          lowerCamelCase__   :						Tuple					   =							None
          for i in range(len(self.key_string			)			):
             if (det * i) % len(self.key_string			) == 1:
                lowerCamelCase__   :						Dict					   =							i
                break

          lowerCamelCase__   :						Any					   =							(
              det_inv
              * numpy.linalg.det(self.encrypt_key			)
              * numpy.linalg.inv(self.encrypt_key			)
          )

          return self.to_int(self.modulus(A			)			)







       def 						__lowerCamelCase    (      self     :	Tuple		,					A     :	Optional[Any]			)   ->str:
          lowerCamelCase__   :						Tuple					   =							self.make_decrypt_key()
          lowerCamelCase__   :						Tuple					   =							self.process_text(text.upper()			)
          lowerCamelCase__   :						Tuple					   =							''

          for i in range(0		,					len(A			) - self.break_key + 1		,					self.break_key			):
             lowerCamelCase__   :						Optional[int]					   =							text[i : i + self.break_key]
             lowerCamelCase__   :						Dict					   =							[self.replace_letters(A			) for char in batch]
             lowerCamelCase__   :						int					   =							numpy.array([vec]			).T
             lowerCamelCase__   :						Tuple					   =							self.modulus(decrypt_key.dot(A			)			).T.tolist()[0]
             lowerCamelCase__   :						Optional[Any]					   =							''.join(
                 self.replace_digits(A			) for num in batch_decrypted			)
             decrypted += decrypted_batch

          return decrypted



def        _a						(    )				->				Any:







   """simple docstring"""
   lowerCamelCase__   :						Dict					   =							int(input('''Enter the order of the encryption key: '''     )     )
   lowerCamelCase__   :						List[str]					   =							[]

   print('''Enter each row of the encryption key with space separated integers'''     )
   for _ in range(SCREAMING_SNAKE_CASE_     ):
      lowerCamelCase__   :						Any					   =							[int(SCREAMING_SNAKE_CASE_     ) for x in input().split()]
      hill_matrix.append(SCREAMING_SNAKE_CASE_     )

   lowerCamelCase__   :						List[Any]					   =							HillCipher(numpy.array(SCREAMING_SNAKE_CASE_     )     )

   print('''Would you like to encrypt or decrypt some text? (1 or 2)'''     )
   lowerCamelCase__   :						List[Any]					   =							input('''\n1. Encrypt\n2. Decrypt\n'''     )
   if option == "1":
      lowerCamelCase__   :						Optional[int]					   =							input('''What text would you like to encrypt?: '''     )
      print('''Your encrypted text is:'''     )
      print(hc.encrypt(SCREAMING_SNAKE_CASE_     )     )
   elif option == "2":
      lowerCamelCase__   :						Dict					   =							input('''What text would you like to decrypt?: '''     )
      print('''Your decrypted text is:'''     )
      print(hc.decrypt(SCREAMING_SNAKE_CASE_     )     )


if __name__ == "__main__":
       import doctest

       doctest.testmod()

       main()






import unittest

from transformers import EsmConfig, is_torch_available
from transformers.testing_utils import TestCasePlus, require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
       import torch

       from transformers.models.esm.modeling_esmfold import EsmForProteinFolding


class       SCREAMING_SNAKE_CASE__					:





    def __init__(      self						,   a						,   a=13						,   a=7						,   a=False						,   a=True						,   a=False						,   a=False						,   a=19						,   a=32						,   a=5						,   a=4						,   a=37						,   a="gelu"						,   a=0.1						,   a=0.1						,   a=512						,   a=16						,   a=2						,   a=0.02						,   a=3						,   a=4						,   a=None						,   ):
         lowercase__    :   Optional[Any]      =       parent
         lowercase__    :   Dict      =       batch_size
         lowercase__    :   Union[str, Any]      =       seq_length
         lowercase__    :   Optional[Any]      =       is_training
         lowercase__    :   Tuple      =       use_input_mask
         lowercase__    :   List[str]      =       use_token_type_ids
         lowercase__    :   Optional[Any]      =       use_labels
         lowercase__    :   List[str]      =       vocab_size
         lowercase__    :   Optional[int]      =       hidden_size
         lowercase__    :   List[str]      =       num_hidden_layers
         lowercase__    :   Any      =       num_attention_heads
         lowercase__    :   int      =       intermediate_size
         lowercase__    :   Any      =       hidden_act
         lowercase__    :   Any      =       hidden_dropout_prob
         lowercase__    :   str      =       attention_probs_dropout_prob
         lowercase__    :   List[Any]      =       max_position_embeddings
         lowercase__    :   int      =       type_vocab_size
         lowercase__    :   List[Any]      =       type_sequence_label_size
         lowercase__    :   str      =       initializer_range
         lowercase__    :   List[str]      =       num_labels
         lowercase__    :   Union[str, Any]      =       num_choices
         lowercase__    :   Optional[int]      =       scope





    def       snake_case_				(      self):
         lowercase__    :   List[Any]      =       ids_tensor([self.batch_size, self.seq_length]						,   self.vocab_size)

         lowercase__    :   List[Any]      =       None
         if self.use_input_mask:
              lowercase__    :   Union[str, Any]      =       random_attention_mask([self.batch_size, self.seq_length])

         lowercase__    :   int      =       None
         lowercase__    :   Optional[int]      =       None
         lowercase__    :   Optional[int]      =       None
         if self.use_labels:
              lowercase__    :   Optional[int]      =       ids_tensor([self.batch_size]						,   self.type_sequence_label_size)
              lowercase__    :   str      =       ids_tensor([self.batch_size, self.seq_length]						,   self.num_labels)
              lowercase__    :   str      =       ids_tensor([self.batch_size]						,   self.num_choices)

         lowercase__    :   int      =       self.get_config()

         return config, input_ids, input_mask, sequence_labels, token_labels, choice_labels





    def       snake_case_				(      self):
         lowercase__    :   str      =       EsmConfig(
             vocab_size=33						,   hidden_size=self.hidden_size						,   pad_token_id=1						,   num_hidden_layers=self.num_hidden_layers						,   num_attention_heads=self.num_attention_heads						,   intermediate_size=self.intermediate_size						,   hidden_act=self.hidden_act						,   hidden_dropout_prob=self.hidden_dropout_prob						,   attention_probs_dropout_prob=self.attention_probs_dropout_prob						,   max_position_embeddings=self.max_position_embeddings						,   type_vocab_size=self.type_vocab_size						,   initializer_range=self.initializer_range						,   is_folding_model=a						,   esmfold_config={'trunk': {'num_blocks': 2}, 'fp16_esm': False}						,   )
         return config





    def       snake_case_				(      self						,   a						,   a						,   a						,   a						,   a						,   a):
         lowercase__    :   Dict      =       EsmForProteinFolding(config=a).float()
         model.to(a)
         model.eval()
         lowercase__    :   Union[str, Any]      =       model(a						,   attention_mask=a)
         lowercase__    :   Dict      =       model(a)
         lowercase__    :   int      =       model(a)

         self.parent.assertEqual(result.positions.shape						,   (8, self.batch_size, self.seq_length, 14, 3))
         self.parent.assertEqual(result.angles.shape						,   (8, self.batch_size, self.seq_length, 7, 2))





    def       snake_case_				(      self):
         lowercase__    :   List[str]      =       self.prepare_config_and_inputs()
         (
             (
             lowercase__
         )      , (
             lowercase__
         )      , (
             lowercase__
         )      , (
             lowercase__
         )      , (
             lowercase__
         )      , (
             lowercase__
         )      , 
         )    :   int      =       config_and_inputs
         lowercase__    :   Optional[int]      =       {'input_ids': input_ids, 'attention_mask': input_mask}
         return config, inputs_dict



@require_torch
class       SCREAMING_SNAKE_CASE__					(__snake_case		,       __snake_case		,       unittest.TestCase     ):
    __lowerCamelCase						:       Dict														=     False

    __lowerCamelCase						:       Dict														=     (EsmForProteinFolding,) if is_torch_available() else ()
    __lowerCamelCase						:       Union[str, Any]														=     ()
    __lowerCamelCase						:       List[Any]														=     {} if is_torch_available() else {}
    __lowerCamelCase						:       Optional[Any]														=     False





    def       snake_case_				(      self):
         lowercase__    :   Tuple      =       EsmFoldModelTester(self)
         lowercase__    :   List[Any]      =       ConfigTester(self						,   config_class=a						,   hidden_size=37)





    def       snake_case_				(      self):
         self.config_tester.run_common_tests()





    def       snake_case_				(      self):
         lowercase__    :   Optional[int]      =       self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_model(*a)





    @unittest.skip('Does not support attention outputs')
    def       snake_case_				(      self):
         pass





    @unittest.skip
    def       snake_case_				(      self):
         pass





    @unittest.skip('Esm does not support embedding resizing')
    def       snake_case_				(      self):
         pass





    @unittest.skip('Esm does not support embedding resizing')
    def       snake_case_				(      self):
         pass





    @unittest.skip('ESMFold does not support passing input embeds!')
    def       snake_case_				(      self):
         pass





    @unittest.skip('ESMFold does not support head pruning.')
    def       snake_case_				(      self):
         pass





    @unittest.skip('ESMFold does not support head pruning.')
    def       snake_case_				(      self):
         pass





    @unittest.skip('ESMFold does not support head pruning.')
    def       snake_case_				(      self):
         pass





    @unittest.skip('ESMFold does not support head pruning.')
    def       snake_case_				(      self):
         pass





    @unittest.skip('ESMFold does not support head pruning.')
    def       snake_case_				(      self):
         pass





    @unittest.skip('ESMFold does not output hidden states in the normal way.')
    def       snake_case_				(      self):
         pass





    @unittest.skip('ESMfold does not output hidden states in the normal way.')
    def       snake_case_				(      self):
         pass





    @unittest.skip('ESMFold only has one output format.')
    def       snake_case_				(      self):
         pass





    @unittest.skip('This test doesn\'t work for ESMFold and doesn\'t test core functionality')
    def       snake_case_				(      self):
         pass





    @unittest.skip('ESMFold does not support input chunking.')
    def       snake_case_				(      self):
         pass





    @unittest.skip('ESMFold doesn\'t respect you and it certainly doesn\'t respect your initialization arguments.')
    def       snake_case_				(      self):
         pass





    @unittest.skip('ESMFold doesn\'t support torchscript compilation.')
    def       snake_case_				(      self):
         pass





    @unittest.skip('ESMFold doesn\'t support torchscript compilation.')
    def       snake_case_				(      self):
         pass





    @unittest.skip('ESMFold doesn\'t support torchscript compilation.')
    def       snake_case_				(      self):
         pass





    @unittest.skip('ESMFold doesn\'t support data parallel.')
    def       snake_case_				(      self):
         pass





    @unittest.skip('Will be fixed soon by reducing the size of the model used for common tests.')
    def       snake_case_				(      self):
         pass



@require_torch
class       SCREAMING_SNAKE_CASE__					(__snake_case     ):





    @slow
    def       snake_case_				(      self):
         lowercase__    :   Dict      =       EsmForProteinFolding.from_pretrained('facebook/esmfold_v1').float()
         model.eval()
         lowercase__    :   Optional[Any]      =       torch.tensor([[0, 6, 4, 13, 5, 4, 16, 12, 11, 7, 2]])
         lowercase__    :   Optional[int]      =       model(a)['positions']
         lowercase__    :   Dict      =       torch.tensor([2.5_828, 0.7_993, -10.9_334]						,   dtype=torch.floataa)
         self.assertTrue(torch.allclose(position_outputs[0, 0, 0, 0]						,   a						,   atol=1e-4))

