





import string

import numpy

def 							SCREAMING_SNAKE_CASE__       (  snake_case__  :int			,							snake_case__  :int     )      ->						int:
  return b if a == 0 else greatest_common_divisor(b % a			,							snake_case__     )





class 				A_				:







       """simple docstring"""





       SCREAMING_SNAKE_CASE_      : 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)
       SCREAMING_SNAKE_CASE_      : Dict      =  numpy.vectorize(lambda UpperCAmelCase	: x % 3_6	)

       SCREAMING_SNAKE_CASE_      : List[Any]      =  numpy.vectorize(UpperCAmelCase	)







       def __init__(    self	:	Optional[Any]						,__A	:	numpy.ndarray  )						->					None:
         _lowercase							= self.modulus(__A  )  # mod36 calc's on the encrypt key
         self.check_determinant()  # validate the determinant of the encryption key
         _lowercase							= encrypt_key.shape[0]







       def    __UpperCAmelCase (    self	:	Tuple						,__A	:	str  )						->					int:
         return self.key_string.index(__A  )







       def    __UpperCAmelCase (    self	:	Optional[int]						,__A	:	int  )						->					str:
         return self.key_string[round(__A  )]







       def    __UpperCAmelCase (    self	:	str  )						->					None:
         _lowercase							= round(numpy.linalg.det(self.encrypt_key  )  )

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

         _lowercase							= len(self.key_string  )
         if greatest_common_divisor(__A						,len(self.key_string  )  ) != 1:
           _lowercase							= (
               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	:	Any						,__A	:	str  )						->					str:
         _lowercase							= [char for char in text.upper() if char in self.key_string]

         _lowercase							= chars[-1]
         while len(__A  ) % self.break_key != 0:
           chars.append(__A  )

         return "".join(__A  )







       def    __UpperCAmelCase (    self	:	Optional[int]						,__A	:	str  )						->					str:
         _lowercase							= self.process_text(text.upper()  )
         _lowercase							= ''

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

         return encrypted







       def    __UpperCAmelCase (    self	:	List[Any]  )						->					numpy.ndarray:
         _lowercase							= round(numpy.linalg.det(self.encrypt_key  )  )

         if det < 0:
           _lowercase							= det % len(self.key_string  )
         _lowercase							= None
         for i in range(len(self.key_string  )  ):
           if (det * i) % len(self.key_string  ) == 1:
             _lowercase							= i
             break

         _lowercase							= (
             det_inv
             * numpy.linalg.det(self.encrypt_key  )
             * numpy.linalg.inv(self.encrypt_key  )
         )

         return self.to_int(self.modulus(__A  )  )







       def    __UpperCAmelCase (    self	:	Tuple						,__A	:	str  )						->					str:
         _lowercase							= self.make_decrypt_key()
         _lowercase							= self.process_text(text.upper()  )
         _lowercase							= ''

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

         return decrypted

def 							SCREAMING_SNAKE_CASE__       (  )      ->						None:
  _lowercase							= int(input('Enter the order of the encryption key: '     )     )
  _lowercase							= []

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

  _lowercase							= HillCipher(numpy.array(snake_case__     )     )

  print('Would you like to encrypt or decrypt some text? (1 or 2)'     )
  _lowercase							= input('\n1. Encrypt\n2. Decrypt\n'     )
  if option == "1":
    _lowercase							= input('What text would you like to encrypt?: '     )
    print('Your encrypted text is:'     )
    print(hc.encrypt(snake_case__     )     )
  elif option == "2":
    _lowercase							= 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()








snake_case 				=       """0.18.2"""

from .configuration_utils import ConfigMixin
from .utils import (
    OptionalDependencyNotAvailable,
    is_flax_available,
    is_inflect_available,
    is_invisible_watermark_available,
    is_k_diffusion_available,
    is_k_diffusion_version,
    is_librosa_available,
    is_note_seq_available,
    is_onnx_available,
    is_scipy_available,
    is_torch_available,
    is_torchsde_available,
    is_transformers_available,
    is_transformers_version,
    is_unidecode_available,
    logging,
)


try:
      if not is_onnx_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      from .utils.dummy_onnx_objects import *  # noqa F403
else:
      from .pipelines import OnnxRuntimeModel

try:
      if not is_torch_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      from .utils.dummy_pt_objects import *  # noqa F403
else:
      from .models import (
          AutoencoderKL,
          ControlNetModel,
          ModelMixin,
          PriorTransformer,
          TaFilmDecoder,
          TransformeraDModel,
          UNetaDModel,
          UNetaDConditionModel,
          UNetaDModel,
          UNetaDConditionModel,
          VQModel,
      )
      from .optimization import (
          get_constant_schedule,
          get_constant_schedule_with_warmup,
          get_cosine_schedule_with_warmup,
          get_cosine_with_hard_restarts_schedule_with_warmup,
          get_linear_schedule_with_warmup,
          get_polynomial_decay_schedule_with_warmup,
          get_scheduler,
      )
      from .pipelines import (
          AudioPipelineOutput,
          ConsistencyModelPipeline,
          DanceDiffusionPipeline,
          DDIMPipeline,
          DDPMPipeline,
          DiffusionPipeline,
          DiTPipeline,
          ImagePipelineOutput,
          KarrasVePipeline,
          LDMPipeline,
          LDMSuperResolutionPipeline,
          PNDMPipeline,
          RePaintPipeline,
          ScoreSdeVePipeline,
      )
      from .schedulers import (
          CMStochasticIterativeScheduler,
          DDIMInverseScheduler,
          DDIMParallelScheduler,
          DDIMScheduler,
          DDPMParallelScheduler,
          DDPMScheduler,
          DEISMultistepScheduler,
          DPMSolverMultistepInverseScheduler,
          DPMSolverMultistepScheduler,
          DPMSolverSinglestepScheduler,
          EulerAncestralDiscreteScheduler,
          EulerDiscreteScheduler,
          HeunDiscreteScheduler,
          IPNDMScheduler,
          KarrasVeScheduler,
          KDPMaAncestralDiscreteScheduler,
          KDPMaDiscreteScheduler,
          PNDMScheduler,
          RePaintScheduler,
          SchedulerMixin,
          ScoreSdeVeScheduler,
          UnCLIPScheduler,
          UniPCMultistepScheduler,
          VQDiffusionScheduler,
      )
      from .training_utils import EMAModel

try:
      if not (is_torch_available() and is_scipy_available()):
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      from .utils.dummy_torch_and_scipy_objects import *  # noqa F403
else:
      from .schedulers import LMSDiscreteScheduler

try:
      if not (is_torch_available() and is_torchsde_available()):
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      from .utils.dummy_torch_and_torchsde_objects import *  # noqa F403
else:
      from .schedulers import DPMSolverSDEScheduler

try:
      if not (is_torch_available() and is_transformers_available()):
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      from .utils.dummy_torch_and_transformers_objects import *  # noqa F403
else:
      from .pipelines import (
          AltDiffusionImgaImgPipeline,
          AltDiffusionPipeline,
          AudioLDMPipeline,
          CycleDiffusionPipeline,
          IFImgaImgPipeline,
          IFImgaImgSuperResolutionPipeline,
          IFInpaintingPipeline,
          IFInpaintingSuperResolutionPipeline,
          IFPipeline,
          IFSuperResolutionPipeline,
          ImageTextPipelineOutput,
          KandinskyImgaImgPipeline,
          KandinskyInpaintPipeline,
          KandinskyPipeline,
          KandinskyPriorPipeline,
          KandinskyVaaControlnetImgaImgPipeline,
          KandinskyVaaControlnetPipeline,
          KandinskyVaaImgaImgPipeline,
          KandinskyVaaInpaintPipeline,
          KandinskyVaaPipeline,
          KandinskyVaaPriorEmbaEmbPipeline,
          KandinskyVaaPriorPipeline,
          LDMTextToImagePipeline,
          PaintByExamplePipeline,
          SemanticStableDiffusionPipeline,
          ShapEImgaImgPipeline,
          ShapEPipeline,
          StableDiffusionAttendAndExcitePipeline,
          StableDiffusionControlNetImgaImgPipeline,
          StableDiffusionControlNetInpaintPipeline,
          StableDiffusionControlNetPipeline,
          StableDiffusionDepthaImgPipeline,
          StableDiffusionDiffEditPipeline,
          StableDiffusionImageVariationPipeline,
          StableDiffusionImgaImgPipeline,
          StableDiffusionInpaintPipeline,
          StableDiffusionInpaintPipelineLegacy,
          StableDiffusionInstructPixaPixPipeline,
          StableDiffusionLatentUpscalePipeline,
          StableDiffusionLDMaDPipeline,
          StableDiffusionModelEditingPipeline,
          StableDiffusionPanoramaPipeline,
          StableDiffusionParadigmsPipeline,
          StableDiffusionPipeline,
          StableDiffusionPipelineSafe,
          StableDiffusionPixaPixZeroPipeline,
          StableDiffusionSAGPipeline,
          StableDiffusionUpscalePipeline,
          StableUnCLIPImgaImgPipeline,
          StableUnCLIPPipeline,
          TextToVideoSDPipeline,
          TextToVideoZeroPipeline,
          UnCLIPImageVariationPipeline,
          UnCLIPPipeline,
          UniDiffuserModel,
          UniDiffuserPipeline,
          UniDiffuserTextDecoder,
          VersatileDiffusionDualGuidedPipeline,
          VersatileDiffusionImageVariationPipeline,
          VersatileDiffusionPipeline,
          VersatileDiffusionTextToImagePipeline,
          VideoToVideoSDPipeline,
          VQDiffusionPipeline,
      )

try:
      if not (is_torch_available() and is_transformers_available() and is_invisible_watermark_available()):
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      from .utils.dummy_torch_and_transformers_and_invisible_watermark_objects import *  # noqa F403
else:
      from .pipelines import StableDiffusionXLImgaImgPipeline, StableDiffusionXLPipeline

try:
      if not (is_torch_available() and is_transformers_available() and is_k_diffusion_available()):
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      from .utils.dummy_torch_and_transformers_and_k_diffusion_objects import *  # noqa F403
else:
      from .pipelines import StableDiffusionKDiffusionPipeline

try:
      if not (is_torch_available() and is_transformers_available() and is_onnx_available()):
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      from .utils.dummy_torch_and_transformers_and_onnx_objects import *  # noqa F403
else:
      from .pipelines import (
          OnnxStableDiffusionImgaImgPipeline,
          OnnxStableDiffusionInpaintPipeline,
          OnnxStableDiffusionInpaintPipelineLegacy,
          OnnxStableDiffusionPipeline,
          OnnxStableDiffusionUpscalePipeline,
          StableDiffusionOnnxPipeline,
      )

try:
      if not (is_torch_available() and is_librosa_available()):
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      from .utils.dummy_torch_and_librosa_objects import *  # noqa F403
else:
      from .pipelines import AudioDiffusionPipeline, Mel

try:
      if not (is_transformers_available() and is_torch_available() and is_note_seq_available()):
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      from .utils.dummy_transformers_and_torch_and_note_seq_objects import *  # noqa F403
else:
      from .pipelines import SpectrogramDiffusionPipeline

try:
      if not is_flax_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      from .utils.dummy_flax_objects import *  # noqa F403
else:
      from .models.controlnet_flax import FlaxControlNetModel
      from .models.modeling_flax_utils import FlaxModelMixin
      from .models.unet_ad_condition_flax import FlaxUNetaDConditionModel
      from .models.vae_flax import FlaxAutoencoderKL
      from .pipelines import FlaxDiffusionPipeline
      from .schedulers import (
          FlaxDDIMScheduler,
          FlaxDDPMScheduler,
          FlaxDPMSolverMultistepScheduler,
          FlaxKarrasVeScheduler,
          FlaxLMSDiscreteScheduler,
          FlaxPNDMScheduler,
          FlaxSchedulerMixin,
          FlaxScoreSdeVeScheduler,
      )


try:
      if not (is_flax_available() and is_transformers_available()):
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      from .utils.dummy_flax_and_transformers_objects import *  # noqa F403
else:
      from .pipelines import (
          FlaxStableDiffusionControlNetPipeline,
          FlaxStableDiffusionImgaImgPipeline,
          FlaxStableDiffusionInpaintPipeline,
          FlaxStableDiffusionPipeline,
      )

try:
      if not (is_note_seq_available()):
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      from .utils.dummy_note_seq_objects import *  # noqa F403
else:
      from .pipelines import MidiProcessor