
import argparse
import struct
import unittest





class     __UpperCamelCase :






     """simple docstring"""







     def __init__(				self							:							Union[str, Any]     ,						_A							:							bytes ):







       """simple docstring"""




       __SCREAMING_SNAKE_CASE      :	Optional[Any]					=		data

       # Initialize hash values
       __SCREAMING_SNAKE_CASE      :	List[str]					=		[
           0x6A_09_E6_67,
           0xBB_67_AE_85,
           0x3C_6E_F3_72,
           0xA5_4F_F5_3A,
           0x51_0E_52_7F,
           0x9B_05_68_8C,
           0x1F_83_D9_AB,
           0x5B_E0_CD_19,
       ]

       # Initialize round constants
       __SCREAMING_SNAKE_CASE      :	List[str]					=		[
           0x42_8A_2F_98,
           0x71_37_44_91,
           0xB5_C0_FB_CF,
           0xE9_B5_DB_A5,
           0x39_56_C2_5B,
           0x59_F1_11_F1,
           0x92_3F_82_A4,
           0xAB_1C_5E_D5,
           0xD8_07_AA_98,
           0x12_83_5B_01,
           0x24_31_85_BE,
           0x55_0C_7D_C3,
           0x72_BE_5D_74,
           0x80_DE_B1_FE,
           0x9B_DC_06_A7,
           0xC1_9B_F1_74,
           0xE4_9B_69_C1,
           0xEF_BE_47_86,
           0x0F_C1_9D_C6,
           0x24_0C_A1_CC,
           0x2D_E9_2C_6F,
           0x4A_74_84_AA,
           0x5C_B0_A9_DC,
           0x76_F9_88_DA,
           0x98_3E_51_52,
           0xA8_31_C6_6D,
           0xB0_03_27_C8,
           0xBF_59_7F_C7,
           0xC6_E0_0B_F3,
           0xD5_A7_91_47,
           0x06_CA_63_51,
           0x14_29_29_67,
           0x27_B7_0A_85,
           0x2E_1B_21_38,
           0x4D_2C_6D_FC,
           0x53_38_0D_13,
           0x65_0A_73_54,
           0x76_6A_0A_BB,
           0x81_C2_C9_2E,
           0x92_72_2C_85,
           0xA2_BF_E8_A1,
           0xA8_1A_66_4B,
           0xC2_4B_8B_70,
           0xC7_6C_51_A3,
           0xD1_92_E8_19,
           0xD6_99_06_24,
           0xF4_0E_35_85,
           0x10_6A_A0_70,
           0x19_A4_C1_16,
           0x1E_37_6C_08,
           0x27_48_77_4C,
           0x34_B0_BC_B5,
           0x39_1C_0C_B3,
           0x4E_D8_AA_4A,
           0x5B_9C_CA_4F,
           0x68_2E_6F_F3,
           0x74_8F_82_EE,
           0x78_A5_63_6F,
           0x84_C8_78_14,
           0x8C_C7_02_08,
           0x90_BE_FF_FA,
           0xA4_50_6C_EB,
           0xBE_F9_A3_F7,
           0xC6_71_78_F2,
       ]

       __SCREAMING_SNAKE_CASE      :	List[Any]					=		self.preprocessing(self.data )
       self.final_hash()



     @staticmethod
     def  UpperCAmelCase__							(				_A							:							bytes ):







       """simple docstring"""




       __SCREAMING_SNAKE_CASE      :	Any					=		B'''\x80''' + (B'''\x00''' * (63 - (len(_A ) + 8) % 64))
       __SCREAMING_SNAKE_CASE      :	Optional[int]					=		struct.pack('''>Q'''     ,						(len(_A ) * 8) )
       return data + padding + big_endian_integer



     def  UpperCAmelCase__							(				self							:							Tuple ):







       """simple docstring"""




       __SCREAMING_SNAKE_CASE      :	Dict					=		[
           self.preprocessed_data[x : x + 64]
           for x in range(0     ,						len(self.preprocessed_data )     ,						64 )
       ]

       for block in self.blocks:
         # Convert the given block into a list of 4 byte integers
         __SCREAMING_SNAKE_CASE      :	Dict					=		list(struct.unpack('''>16L'''     ,						_A ) )
         # add 48 0-ed integers
         words += [0] * 48

         __SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE      :	List[str]					=		self.hashes

         for index in range(0     ,						64 ):
           if index > 15:
             # modify the zero-ed indexes at the end of the array
             __SCREAMING_SNAKE_CASE      :	Union[str, Any]					=		(
                 self.ror(words[index - 15]     ,						7 )
                 ^ self.ror(words[index - 15]     ,						18 )
                 ^ (words[index - 15] >> 3)
             )
             __SCREAMING_SNAKE_CASE      :	Optional[int]					=		(
                 self.ror(words[index - 2]     ,						17 )
                 ^ self.ror(words[index - 2]     ,						19 )
                 ^ (words[index - 2] >> 10)
             )

             __SCREAMING_SNAKE_CASE      :	Union[str, Any]					=		(
                 words[index - 16] + sa + words[index - 7] + sa
             ) % 0x1_00_00_00_00

           # Compression
           __SCREAMING_SNAKE_CASE      :	Any					=		self.ror(_A     ,						6 ) ^ self.ror(_A     ,						11 ) ^ self.ror(_A     ,						25 )
           __SCREAMING_SNAKE_CASE      :	int					=		(e & f) ^ ((~e & 0xFF_FF_FF_FF) & g)
           __SCREAMING_SNAKE_CASE      :	List[str]					=		(
               h + sa + ch + self.round_constants[index] + words[index]
           ) % 0x1_00_00_00_00
           __SCREAMING_SNAKE_CASE      :	Dict					=		self.ror(_A     ,						2 ) ^ self.ror(_A     ,						13 ) ^ self.ror(_A     ,						22 )
           __SCREAMING_SNAKE_CASE      :	str					=		(a & b) ^ (a & c) ^ (b & c)
           __SCREAMING_SNAKE_CASE      :	Dict					=		(sa + maj) % 0x1_00_00_00_00

           __SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE      :	List[Any]					=		(
               g,
               f,
               e,
               ((d + tempa) % 0x1_00_00_00_00),
               c,
               b,
               a,
               ((tempa + tempa) % 0x1_00_00_00_00),
           )

         __SCREAMING_SNAKE_CASE      :	Tuple					=		[a, b, c, d, e, f, g, h]

         # Modify final values
         __SCREAMING_SNAKE_CASE      :	List[str]					=		[
             ((element + mutated_hash_values[index]) % 0x1_00_00_00_00)
             for index, element in enumerate(self.hashes )
         ]

       __SCREAMING_SNAKE_CASE      :	List[Any]					=		''''''.join([hex(_A )[2:].zfill(8 ) for value in self.hashes] )




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







       """simple docstring"""




       return 0xFF_FF_FF_FF & (value << (32 - rotations)) | (value >> rotations)






class     __UpperCamelCase (							unittest.TestCase       ):






     """simple docstring"""







     def  UpperCAmelCase__							(				self							:							Tuple ):







       """simple docstring"""




       import hashlib

       __SCREAMING_SNAKE_CASE      :	Tuple					=		bytes('''Test String'''     ,						'''utf-8''' )
       self.assertEqual(SHAaaa(_A ).hash     ,						hashlib.shaaaa(_A ).hexdigest() )






def 							a__					(							):





  """simple docstring"""
  import doctest

  doctest.testmod()

  __SCREAMING_SNAKE_CASE      :	Any					=		argparse.ArgumentParser()
  parser.add_argument(
      '''-s'''       ,			'''--string'''       ,			dest='''input_string'''       ,			default='''Hello World!! Welcome to Cryptography'''       ,			help='''Hash the string'''       ,			)
  parser.add_argument(
      '''-f'''       ,			'''--file'''       ,			dest='''input_file'''       ,			help='''Hash contents of a file'''							)

  __SCREAMING_SNAKE_CASE      :	int					=		parser.parse_args()

  __SCREAMING_SNAKE_CASE      :	Tuple					=		args.input_string

  # hash input should be a bytestring
  if args.input_file:
    with open(args.input_file       ,			'''rb'''							) as f:
      __SCREAMING_SNAKE_CASE      :	Union[str, Any]					=		f.read()
  else:
    __SCREAMING_SNAKE_CASE      :	str					=		bytes(snake_case       ,			'''utf-8'''							)

  print(SHAaaa(snake_case							).hash							)


if __name__ == "__main__":
   main()








from typing import Any, Callable, Dict, List, Optional, Union

import torch
from transformers import CLIPImageProcessor, CLIPTextModel, CLIPTokenizer

from diffusers import (
    AutoencoderKL,
    DDIMScheduler,
    DiffusionPipeline,
    LMSDiscreteScheduler,
    PNDMScheduler,
    StableDiffusionPipeline,
    UNetaDConditionModel,
)
from diffusers.pipelines.stable_diffusion import StableDiffusionPipelineOutput
from diffusers.pipelines.stable_diffusion.safety_checker import StableDiffusionSafetyChecker


UpperCamelCase    							=      'CompVis/stable-diffusion-v1-1'
UpperCamelCase    							=      'CompVis/stable-diffusion-v1-2'
UpperCamelCase    							=      'CompVis/stable-diffusion-v1-3'
UpperCamelCase    							=      'CompVis/stable-diffusion-v1-4'







class 		_A						( UpperCAmelCase_ ):

  def __init__(    self						:	List[str]   ,				lowerCamelCase__						:	AutoencoderKL   ,				lowerCamelCase__						:	CLIPTextModel   ,				lowerCamelCase__						:	CLIPTokenizer   ,				lowerCamelCase__						:	UNetaDConditionModel   ,				lowerCamelCase__						:	Union[DDIMScheduler, PNDMScheduler, LMSDiscreteScheduler]   ,				lowerCamelCase__						:	StableDiffusionSafetyChecker   ,				lowerCamelCase__						:	CLIPImageProcessor   ,				lowerCamelCase__						:	bool = True   ,				):
     """simple docstring"""

     super()._init_()

     __UpperCamelCase	:			Optional[Any]					=					StableDiffusionPipeline.from_pretrained(lowerCamelCase__			)
     __UpperCamelCase	:			int					=					StableDiffusionPipeline.from_pretrained(lowerCamelCase__			)
     __UpperCamelCase	:			List[str]					=					StableDiffusionPipeline.from_pretrained(lowerCamelCase__			)
     __UpperCamelCase	:			str					=					StableDiffusionPipeline(
         vae=lowerCamelCase__   ,				text_encoder=lowerCamelCase__   ,				tokenizer=lowerCamelCase__   ,				unet=lowerCamelCase__   ,				scheduler=lowerCamelCase__   ,				safety_checker=lowerCamelCase__   ,				feature_extractor=lowerCamelCase__   ,				requires_safety_checker=lowerCamelCase__   ,				)

     self.register_modules(pipelinea=self.pipea   ,				pipelinea=self.pipea   ,				pipelinea=self.pipea   ,				pipelinea=self.pipea			)

  @property
  def    a					(    self						:	Optional[Any]			):
     """simple docstring"""

     return {k: getattr(self   ,				lowerCamelCase__			) for k in self.config.keys() if not k.startswith("""_"""			)}

  def    a					(    self						:	List[str]   ,				lowerCamelCase__						:	Optional[Union[str, int]] = "auto"			):
     """simple docstring"""

     if slice_size == "auto":
        # half the attention head size is usually a good trade-off between
        # speed and memory
        __UpperCamelCase	:			Dict					=					self.unet.config.attention_head_dim // 2
     self.unet.set_attention_slice(lowerCamelCase__			)

  def    a					(    self						:	str			):
     """simple docstring"""

     self.enable_attention_slicing(lowerCamelCase__			)

  @torch.no_grad()
  def    a					(    self						:	Any   ,				lowerCamelCase__						:	Union[str, List[str]]   ,				lowerCamelCase__						:	int = 5_12   ,				lowerCamelCase__						:	int = 5_12   ,				lowerCamelCase__						:	int = 50   ,				lowerCamelCase__						:	float = 7.5   ,				lowerCamelCase__						:	Optional[Union[str, List[str]]] = None   ,				lowerCamelCase__						:	Optional[int] = 1   ,				lowerCamelCase__						:	float = 0.0   ,				lowerCamelCase__						:	Optional[torch.Generator] = None   ,				lowerCamelCase__						:	Optional[torch.FloatTensor] = None   ,				lowerCamelCase__						:	Optional[str] = "pil"   ,				lowerCamelCase__						:	bool = True   ,				lowerCamelCase__						:	Optional[Callable[[int, int, torch.FloatTensor], None]] = None   ,				lowerCamelCase__						:	int = 1   ,				**lowerCamelCase__						:	str   ,				):
     """simple docstring"""

     return self.pipea(
         prompt=lowerCamelCase__   ,				height=lowerCamelCase__   ,				width=lowerCamelCase__   ,				num_inference_steps=lowerCamelCase__   ,				guidance_scale=lowerCamelCase__   ,				negative_prompt=lowerCamelCase__   ,				num_images_per_prompt=lowerCamelCase__   ,				eta=lowerCamelCase__   ,				generator=lowerCamelCase__   ,				latents=lowerCamelCase__   ,				output_type=lowerCamelCase__   ,				return_dict=lowerCamelCase__   ,				callback=lowerCamelCase__   ,				callback_steps=lowerCamelCase__   ,				**lowerCamelCase__   ,				)

  @torch.no_grad()
  def    a					(    self						:	Union[str, Any]   ,				lowerCamelCase__						:	Union[str, List[str]]   ,				lowerCamelCase__						:	int = 5_12   ,				lowerCamelCase__						:	int = 5_12   ,				lowerCamelCase__						:	int = 50   ,				lowerCamelCase__						:	float = 7.5   ,				lowerCamelCase__						:	Optional[Union[str, List[str]]] = None   ,				lowerCamelCase__						:	Optional[int] = 1   ,				lowerCamelCase__						:	float = 0.0   ,				lowerCamelCase__						:	Optional[torch.Generator] = None   ,				lowerCamelCase__						:	Optional[torch.FloatTensor] = None   ,				lowerCamelCase__						:	Optional[str] = "pil"   ,				lowerCamelCase__						:	bool = True   ,				lowerCamelCase__						:	Optional[Callable[[int, int, torch.FloatTensor], None]] = None   ,				lowerCamelCase__						:	int = 1   ,				**lowerCamelCase__						:	Dict   ,				):
     """simple docstring"""

     return self.pipea(
         prompt=lowerCamelCase__   ,				height=lowerCamelCase__   ,				width=lowerCamelCase__   ,				num_inference_steps=lowerCamelCase__   ,				guidance_scale=lowerCamelCase__   ,				negative_prompt=lowerCamelCase__   ,				num_images_per_prompt=lowerCamelCase__   ,				eta=lowerCamelCase__   ,				generator=lowerCamelCase__   ,				latents=lowerCamelCase__   ,				output_type=lowerCamelCase__   ,				return_dict=lowerCamelCase__   ,				callback=lowerCamelCase__   ,				callback_steps=lowerCamelCase__   ,				**lowerCamelCase__   ,				)

  @torch.no_grad()
  def    a					(    self						:	Union[str, Any]   ,				lowerCamelCase__						:	Union[str, List[str]]   ,				lowerCamelCase__						:	int = 5_12   ,				lowerCamelCase__						:	int = 5_12   ,				lowerCamelCase__						:	int = 50   ,				lowerCamelCase__						:	float = 7.5   ,				lowerCamelCase__						:	Optional[Union[str, List[str]]] = None   ,				lowerCamelCase__						:	Optional[int] = 1   ,				lowerCamelCase__						:	float = 0.0   ,				lowerCamelCase__						:	Optional[torch.Generator] = None   ,				lowerCamelCase__						:	Optional[torch.FloatTensor] = None   ,				lowerCamelCase__						:	Optional[str] = "pil"   ,				lowerCamelCase__						:	bool = True   ,				lowerCamelCase__						:	Optional[Callable[[int, int, torch.FloatTensor], None]] = None   ,				lowerCamelCase__						:	int = 1   ,				**lowerCamelCase__						:	Any   ,				):
     """simple docstring"""

     return self.pipea(
         prompt=lowerCamelCase__   ,				height=lowerCamelCase__   ,				width=lowerCamelCase__   ,				num_inference_steps=lowerCamelCase__   ,				guidance_scale=lowerCamelCase__   ,				negative_prompt=lowerCamelCase__   ,				num_images_per_prompt=lowerCamelCase__   ,				eta=lowerCamelCase__   ,				generator=lowerCamelCase__   ,				latents=lowerCamelCase__   ,				output_type=lowerCamelCase__   ,				return_dict=lowerCamelCase__   ,				callback=lowerCamelCase__   ,				callback_steps=lowerCamelCase__   ,				**lowerCamelCase__   ,				)

  @torch.no_grad()
  def    a					(    self						:	Dict   ,				lowerCamelCase__						:	Union[str, List[str]]   ,				lowerCamelCase__						:	int = 5_12   ,				lowerCamelCase__						:	int = 5_12   ,				lowerCamelCase__						:	int = 50   ,				lowerCamelCase__						:	float = 7.5   ,				lowerCamelCase__						:	Optional[Union[str, List[str]]] = None   ,				lowerCamelCase__						:	Optional[int] = 1   ,				lowerCamelCase__						:	float = 0.0   ,				lowerCamelCase__						:	Optional[torch.Generator] = None   ,				lowerCamelCase__						:	Optional[torch.FloatTensor] = None   ,				lowerCamelCase__						:	Optional[str] = "pil"   ,				lowerCamelCase__						:	bool = True   ,				lowerCamelCase__						:	Optional[Callable[[int, int, torch.FloatTensor], None]] = None   ,				lowerCamelCase__						:	int = 1   ,				**lowerCamelCase__						:	List[Any]   ,				):
     """simple docstring"""

     return self.pipea(
         prompt=lowerCamelCase__   ,				height=lowerCamelCase__   ,				width=lowerCamelCase__   ,				num_inference_steps=lowerCamelCase__   ,				guidance_scale=lowerCamelCase__   ,				negative_prompt=lowerCamelCase__   ,				num_images_per_prompt=lowerCamelCase__   ,				eta=lowerCamelCase__   ,				generator=lowerCamelCase__   ,				latents=lowerCamelCase__   ,				output_type=lowerCamelCase__   ,				return_dict=lowerCamelCase__   ,				callback=lowerCamelCase__   ,				callback_steps=lowerCamelCase__   ,				**lowerCamelCase__   ,				)

  @torch.no_grad()
  def    a					(    self						:	Optional[Any]   ,				lowerCamelCase__						:	Union[str, List[str]]   ,				lowerCamelCase__						:	int = 5_12   ,				lowerCamelCase__						:	int = 5_12   ,				lowerCamelCase__						:	int = 50   ,				lowerCamelCase__						:	float = 7.5   ,				lowerCamelCase__						:	Optional[Union[str, List[str]]] = None   ,				lowerCamelCase__						:	Optional[int] = 1   ,				lowerCamelCase__						:	float = 0.0   ,				lowerCamelCase__						:	Optional[torch.Generator] = None   ,				lowerCamelCase__						:	Optional[torch.FloatTensor] = None   ,				lowerCamelCase__						:	Optional[str] = "pil"   ,				lowerCamelCase__						:	bool = True   ,				lowerCamelCase__						:	Optional[Callable[[int, int, torch.FloatTensor], None]] = None   ,				lowerCamelCase__						:	int = 1   ,				**lowerCamelCase__						:	Dict   ,				):
     """simple docstring"""

     __UpperCamelCase	:			Optional[Any]					=					"""cuda""" if torch.cuda.is_available() else """cpu"""
     self.to(lowerCamelCase__			)

     # Checks if the height and width are divisible by 8 or not
     if height % 8 != 0 or width % 8 != 0:
        raise ValueError(f'`height` and `width` must be divisible by 8 but are {height} and {width}.'			)

     # Get first result from Stable Diffusion Checkpoint v1.1
     __UpperCamelCase	:			Optional[int]					=					self.textaimg_sda_a(
         prompt=lowerCamelCase__   ,				height=lowerCamelCase__   ,				width=lowerCamelCase__   ,				num_inference_steps=lowerCamelCase__   ,				guidance_scale=lowerCamelCase__   ,				negative_prompt=lowerCamelCase__   ,				num_images_per_prompt=lowerCamelCase__   ,				eta=lowerCamelCase__   ,				generator=lowerCamelCase__   ,				latents=lowerCamelCase__   ,				output_type=lowerCamelCase__   ,				return_dict=lowerCamelCase__   ,				callback=lowerCamelCase__   ,				callback_steps=lowerCamelCase__   ,				**lowerCamelCase__   ,				)

     # Get first result from Stable Diffusion Checkpoint v1.2
     __UpperCamelCase	:			int					=					self.textaimg_sda_a(
         prompt=lowerCamelCase__   ,				height=lowerCamelCase__   ,				width=lowerCamelCase__   ,				num_inference_steps=lowerCamelCase__   ,				guidance_scale=lowerCamelCase__   ,				negative_prompt=lowerCamelCase__   ,				num_images_per_prompt=lowerCamelCase__   ,				eta=lowerCamelCase__   ,				generator=lowerCamelCase__   ,				latents=lowerCamelCase__   ,				output_type=lowerCamelCase__   ,				return_dict=lowerCamelCase__   ,				callback=lowerCamelCase__   ,				callback_steps=lowerCamelCase__   ,				**lowerCamelCase__   ,				)

     # Get first result from Stable Diffusion Checkpoint v1.3
     __UpperCamelCase	:			Optional[Any]					=					self.textaimg_sda_a(
         prompt=lowerCamelCase__   ,				height=lowerCamelCase__   ,				width=lowerCamelCase__   ,				num_inference_steps=lowerCamelCase__   ,				guidance_scale=lowerCamelCase__   ,				negative_prompt=lowerCamelCase__   ,				num_images_per_prompt=lowerCamelCase__   ,				eta=lowerCamelCase__   ,				generator=lowerCamelCase__   ,				latents=lowerCamelCase__   ,				output_type=lowerCamelCase__   ,				return_dict=lowerCamelCase__   ,				callback=lowerCamelCase__   ,				callback_steps=lowerCamelCase__   ,				**lowerCamelCase__   ,				)

     # Get first result from Stable Diffusion Checkpoint v1.4
     __UpperCamelCase	:			List[Any]					=					self.textaimg_sda_a(
         prompt=lowerCamelCase__   ,				height=lowerCamelCase__   ,				width=lowerCamelCase__   ,				num_inference_steps=lowerCamelCase__   ,				guidance_scale=lowerCamelCase__   ,				negative_prompt=lowerCamelCase__   ,				num_images_per_prompt=lowerCamelCase__   ,				eta=lowerCamelCase__   ,				generator=lowerCamelCase__   ,				latents=lowerCamelCase__   ,				output_type=lowerCamelCase__   ,				return_dict=lowerCamelCase__   ,				callback=lowerCamelCase__   ,				callback_steps=lowerCamelCase__   ,				**lowerCamelCase__   ,				)

     # Get all result images into a single list and pass it via StableDiffusionPipelineOutput for final result
     return StableDiffusionPipelineOutput([resa[0], resa[0], resa[0], resa[0]]			)



