
import string

import numpy


def 							a__					(							snake_case       ,			snake_case							):





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





class     __UpperCamelCase :






     """simple docstring"""







     lowerCAmelCase_							   =			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)
     lowerCAmelCase_							   =			numpy.vectorize(lambda lowerCAmelCase__       : x % 36       )

     lowerCAmelCase_							   =			numpy.vectorize(lowerCAmelCase__       )



     def __init__(				self							:							List[Any]     ,						_A							:							numpy.ndarray ):







       """simple docstring"""




       __SCREAMING_SNAKE_CASE      :	List[Any]					=		self.modulus(_A )  # mod36 calc's on the encrypt key
       self.check_determinant()  # validate the determinant of the encryption key
       __SCREAMING_SNAKE_CASE      :	str					=		encrypt_key.shape[0]



     def  UpperCAmelCase__							(				self							:							Optional[Any]     ,						_A							:							str ):







       """simple docstring"""




       return self.key_string.index(_A )



     def  UpperCAmelCase__							(				self							:							Union[str, Any]     ,						_A							:							int ):







       """simple docstring"""




       return self.key_string[round(_A )]



     def  UpperCAmelCase__							(				self							:							str ):







       """simple docstring"""




       __SCREAMING_SNAKE_CASE      :	Optional[Any]					=		round(numpy.linalg.det(self.encrypt_key ) )

       if det < 0:
         __SCREAMING_SNAKE_CASE      :	str					=		det % len(self.key_string )

       __SCREAMING_SNAKE_CASE      :	Any					=		len(self.key_string )
       if greatest_common_divisor(_A     ,						len(self.key_string ) ) != 1:
         __SCREAMING_SNAKE_CASE      :	Tuple					=		(
             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  UpperCAmelCase__							(				self							:							Optional[Any]     ,						_A							:							str ):







       """simple docstring"""




       __SCREAMING_SNAKE_CASE      :	Any					=		[char for char in text.upper() if char in self.key_string]

       __SCREAMING_SNAKE_CASE      :	str					=		chars[-1]
       while len(_A ) % self.break_key != 0:
         chars.append(_A )

       return "".join(_A )



     def  UpperCAmelCase__							(				self							:							Any     ,						_A							:							str ):







       """simple docstring"""




       __SCREAMING_SNAKE_CASE      :	List[str]					=		self.process_text(text.upper() )
       __SCREAMING_SNAKE_CASE      :	Optional[Any]					=		''''''

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

       return encrypted



     def  UpperCAmelCase__							(				self							:							Optional[int] ):







       """simple docstring"""




       __SCREAMING_SNAKE_CASE      :	Tuple					=		round(numpy.linalg.det(self.encrypt_key ) )

       if det < 0:
         __SCREAMING_SNAKE_CASE      :	str					=		det % len(self.key_string )
       __SCREAMING_SNAKE_CASE      :	List[Any]					=		None
       for i in range(len(self.key_string ) ):
         if (det * i) % len(self.key_string ) == 1:
           __SCREAMING_SNAKE_CASE      :	Optional[int]					=		i
           break

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

       return self.to_int(self.modulus(_A ) )




     def  UpperCAmelCase__							(				self							:							Any     ,						_A							:							str ):







       """simple docstring"""




       __SCREAMING_SNAKE_CASE      :	Union[str, Any]					=		self.make_decrypt_key()
       __SCREAMING_SNAKE_CASE      :	str					=		self.process_text(text.upper() )
       __SCREAMING_SNAKE_CASE      :	Optional[int]					=		''''''

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

       return decrypted






def 							a__					(							):





  """simple docstring"""
  __SCREAMING_SNAKE_CASE      :	Any					=		int(input('''Enter the order of the encryption key: '''							)							)
  __SCREAMING_SNAKE_CASE      :	Optional[Any]					=		[]

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

  __SCREAMING_SNAKE_CASE      :	Dict					=		HillCipher(numpy.array(snake_case							)							)

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


if __name__ == "__main__":
   import doctest

   doctest.testmod()

   main()


'''simple docstring'''





import functools
import operator

from ...configuration_utils import PretrainedConfig
from ...utils import logging


SCREAMING_SNAKE_CASE     =       logging.get_logger(__name__)

SCREAMING_SNAKE_CASE     =       {
    """microsoft/wavlm-base""": """https://huggingface.co/microsoft/wavlm-base/resolve/main/config.json""",
    # See all WavLM models at https://huggingface.co/models?filter=wavlm
}






class 							UpperCAmelCase_							(    A				):

 '''simple docstring'''
 lowercase_					:    List[str]				=							"wavlm"







 def __init__(					self		:  Optional[int]			,				snake_case__		:  Dict=32			,				snake_case__		:  Optional[Any]=7_68			,				snake_case__		:  Tuple=12			,				snake_case__		:  List[Any]=12			,				snake_case__		:  List[str]=30_72			,				snake_case__		:  Tuple="gelu"			,				snake_case__		:  Optional[Any]=0.1			,				snake_case__		:  List[str]=0.1			,				snake_case__		:  Any=0.1			,				snake_case__		:  List[Any]=0.0			,				snake_case__		:  Dict=0.1			,				snake_case__		:  List[Any]=0.1			,				snake_case__		:  Union[str, Any]=0.02			,				snake_case__		:  int=1e-5			,				snake_case__		:  Dict="group"			,				snake_case__		:  Any="gelu"			,				snake_case__		:  List[Any]=(5_12, 5_12, 5_12, 5_12, 5_12, 5_12, 5_12)			,				snake_case__		:  int=(5, 2, 2, 2, 2, 2, 2)			,				snake_case__		:  Dict=(10, 3, 3, 3, 3, 2, 2)			,				snake_case__		:  Tuple=False			,				snake_case__		:  int=1_28			,				snake_case__		:  Dict=16			,				snake_case__		:  int=3_20			,				snake_case__		:  Dict=8_00			,				snake_case__		:  List[str]=False			,				snake_case__		:  Union[str, Any]=True			,				snake_case__		:  str=0.05			,				snake_case__		:  List[Any]=10			,				snake_case__		:  Tuple=2			,				snake_case__		:  Optional[int]=0.0			,				snake_case__		:  int=10			,				snake_case__		:  Any=3_20			,				snake_case__		:  Dict=2			,				snake_case__		:  Optional[int]=0.1			,				snake_case__		:  Union[str, Any]=1_00			,				snake_case__		:  Dict=2_56			,				snake_case__		:  List[Any]=2_56			,				snake_case__		:  List[str]=0.1			,				snake_case__		:  List[Any]="mean"			,				snake_case__		:  int=False			,				snake_case__		:  Any=False			,				snake_case__		:  Any=2_56			,				snake_case__		:  Union[str, Any]=(5_12, 5_12, 5_12, 5_12, 15_00)			,				snake_case__		:  Union[str, Any]=(5, 3, 3, 1, 1)			,				snake_case__		:  Optional[Any]=(1, 2, 3, 1, 1)			,				snake_case__		:  List[Any]=5_12			,				snake_case__		:  str=80			,				snake_case__		:  Any=0			,				snake_case__		:  str=1			,				snake_case__		:  Union[str, Any]=2			,				snake_case__		:  int=False			,				snake_case__		:  Union[str, Any]=3			,				snake_case__		:  Union[str, Any]=2			,				snake_case__		:  List[str]=3			,				snake_case__		:  List[Any]=None			,				**snake_case__		:  int			,				):



   '''simple docstring'''




   super().__init__(**snake_case__			,				pad_token_id=snake_case__			,				bos_token_id=snake_case__			,				eos_token_id=snake_case__ )
   UpperCAmelCase__      :					Union[str, Any]				       =							hidden_size
   UpperCAmelCase__      :					List[str]				       =							feat_extract_norm
   UpperCAmelCase__      :					int				       =							feat_extract_activation
   UpperCAmelCase__      :					Optional[int]				       =							list(snake_case__ )
   UpperCAmelCase__      :					Tuple				       =							list(snake_case__ )
   UpperCAmelCase__      :					Tuple				       =							list(snake_case__ )
   UpperCAmelCase__      :					Tuple				       =							conv_bias
   UpperCAmelCase__      :					List[Any]				       =							num_buckets
   UpperCAmelCase__      :					Union[str, Any]				       =							max_bucket_distance
   UpperCAmelCase__      :					Tuple				       =							num_conv_pos_embeddings
   UpperCAmelCase__      :					Union[str, Any]				       =							num_conv_pos_embedding_groups
   UpperCAmelCase__      :					Optional[Any]				       =							len(self.conv_dim )
   UpperCAmelCase__      :					Optional[int]				       =							num_hidden_layers
   UpperCAmelCase__      :					Tuple				       =							intermediate_size
   UpperCAmelCase__      :					List[str]				       =							hidden_act
   UpperCAmelCase__      :					List[str]				       =							num_attention_heads
   UpperCAmelCase__      :					Any				       =							hidden_dropout
   UpperCAmelCase__      :					List[Any]				       =							attention_dropout
   UpperCAmelCase__      :					Optional[int]				       =							activation_dropout
   UpperCAmelCase__      :					Optional[Any]				       =							feat_proj_dropout
   UpperCAmelCase__      :					List[str]				       =							final_dropout
   UpperCAmelCase__      :					int				       =							layerdrop
   UpperCAmelCase__      :					int				       =							layer_norm_eps
   UpperCAmelCase__      :					Tuple				       =							initializer_range
   UpperCAmelCase__      :					Union[str, Any]				       =							num_ctc_classes
   UpperCAmelCase__      :					Any				       =							vocab_size
   UpperCAmelCase__      :					Dict				       =							do_stable_layer_norm
   UpperCAmelCase__      :					List[Any]				       =							use_weighted_layer_sum
   UpperCAmelCase__      :					Optional[Any]				       =							classifier_proj_size

   if (
       (len(self.conv_stride ) != self.num_feat_extract_layers)
       or (len(self.conv_kernel ) != self.num_feat_extract_layers)
       or (len(self.conv_dim ) != self.num_feat_extract_layers)
   ):
     raise ValueError(
         "Configuration for convolutional layers is incorrect. It is required that `len(config.conv_dim)` =="
         " `len(config.conv_stride)` == `len(config.conv_kernel)`, but is `len(config.conv_dim) ="
         F""" {len(self.conv_dim )}`, `len(config.conv_stride) = {len(self.conv_stride )}`,"""
         F""" `len(config.conv_kernel) = {len(self.conv_kernel )}`.""" )

   # fine-tuning config parameters for SpecAugment: https://arxiv.org/abs/1904.08779
   UpperCAmelCase__      :					List[str]				       =							apply_spec_augment
   UpperCAmelCase__      :					Union[str, Any]				       =							mask_time_prob
   UpperCAmelCase__      :					List[Any]				       =							mask_time_length
   UpperCAmelCase__      :					List[str]				       =							mask_time_min_masks
   UpperCAmelCase__      :					List[str]				       =							mask_feature_prob
   UpperCAmelCase__      :					Dict				       =							mask_feature_length

   # parameters for pretraining with codevector quantized representations
   UpperCAmelCase__      :					Dict				       =							num_codevectors_per_group
   UpperCAmelCase__      :					Union[str, Any]				       =							num_codevector_groups
   UpperCAmelCase__      :					int				       =							contrastive_logits_temperature
   UpperCAmelCase__      :					List[str]				       =							num_negatives
   UpperCAmelCase__      :					List[str]				       =							codevector_dim
   UpperCAmelCase__      :					List[Any]				       =							proj_codevector_dim
   UpperCAmelCase__      :					List[Any]				       =							diversity_loss_weight

   # ctc loss
   UpperCAmelCase__      :					Tuple				       =							ctc_loss_reduction
   UpperCAmelCase__      :					Any				       =							ctc_zero_infinity

   # adapter
   UpperCAmelCase__      :					int				       =							add_adapter
   UpperCAmelCase__      :					List[Any]				       =							adapter_kernel_size
   UpperCAmelCase__      :					Dict				       =							adapter_stride
   UpperCAmelCase__      :					Dict				       =							num_adapter_layers
   UpperCAmelCase__      :					Union[str, Any]				       =							output_hidden_size or hidden_size

   # SequenceClassification-specific parameter. Feel free to ignore for other classes.
   UpperCAmelCase__      :					str				       =							classifier_proj_size

   # XVector-specific parameters. Feel free to ignore for other classes.
   UpperCAmelCase__      :					Any				       =							list(snake_case__ )
   UpperCAmelCase__      :					List[Any]				       =							list(snake_case__ )
   UpperCAmelCase__      :					List[str]				       =							list(snake_case__ )
   UpperCAmelCase__      :					Dict				       =							xvector_output_dim







 @property
 def 							UpperCamelCase  (					self		:  int ):



   '''simple docstring'''




   return functools.reduce(operator.mul			,				self.conv_stride			,				1 )



