

import argparse
import struct
import unittest






class _UpperCamelCase				:
			'''simple docstring'''







			def __init__(      self				:			Dict   ,   a				:			bytes						)				->							None:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE :   Tuple					  =							data

				# Initialize hash values
				SCREAMING_SNAKE_CASE :   Tuple					  =							[
				    0x6A_09E_667,
				    0xBB_67A_E85,
				    0x3C_6EF_372,
				    0xA5_4FF_53A,
				    0x51_0E5_27F,
				    0x9B_056_88C,
				    0x1F_83D_9AB,
				    0x5B_E0C_D19,
				]

				# Initialize round constants
				SCREAMING_SNAKE_CASE :   str					  =							[
				    0x42_8A2_F98,
				    0x71_374_491,
				    0xB5_C0F_BCF,
				    0xE9_B5D_BA5,
				    0x39_56C_25B,
				    0x59_F11_1F1,
				    0x92_3F8_2A4,
				    0xAB_1C5_ED5,
				    0xD8_07A_A98,
				    0x12_835_B01,
				    0x24_318_5BE,
				    0x55_0C7_DC3,
				    0x72_BE5_D74,
				    0x80_DEB_1FE,
				    0x9B_DC0_6A7,
				    0xC1_9BF_174,
				    0xE4_9B6_9C1,
				    0xEF_BE4_786,
				    0x0F_C19_DC6,
				    0x24_0CA_1CC,
				    0x2D_E92_C6F,
				    0x4A_748_4AA,
				    0x5C_B0A_9DC,
				    0x76_F98_8DA,
				    0x98_3E5_152,
				    0xA8_31C_66D,
				    0xB0_032_7C8,
				    0xBF_597_FC7,
				    0xC6_E00_BF3,
				    0xD5_A79_147,
				    0x06_CA6_351,
				    0x14_292_967,
				    0x27_B70_A85,
				    0x2E_1B2_138,
				    0x4D_2C6_DFC,
				    0x53_380_D13,
				    0x65_0A7_354,
				    0x76_6A0_ABB,
				    0x81_C2C_92E,
				    0x92_722_C85,
				    0xA2_BFE_8A1,
				    0xA8_1A6_64B,
				    0xC2_4B8_B70,
				    0xC7_6C5_1A3,
				    0xD1_92E_819,
				    0xD6_990_624,
				    0xF4_0E3_585,
				    0x10_6AA_070,
				    0x19_A4C_116,
				    0x1E_376_C08,
				    0x27_487_74C,
				    0x34_B0B_CB5,
				    0x39_1C0_CB3,
				    0x4E_D8A_A4A,
				    0x5B_9CC_A4F,
				    0x68_2E6_FF3,
				    0x74_8F8_2EE,
				    0x78_A56_36F,
				    0x84_C87_814,
				    0x8C_C70_208,
				    0x90_BEF_FFA,
				    0xA4_506_CEB,
				    0xBE_F9A_3F7,
				    0xC6_717_8F2,
				]

				SCREAMING_SNAKE_CASE :   Tuple					  =							self.preprocessing(self.data						)
				self.final_hash()
			@staticmethod
			def 				__UpperCamelCase			(      a				:			bytes						)				->							bytes:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE :   Optional[int]					  =							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				:			int						)				->							None:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE :   List[Any]					  =							[
				    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 :   Any					  =							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 :   Union[str, Any]					  =							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 :   str					  =							(
							    self.ror(words[index - 15]   ,   7						)
							    ^ self.ror(words[index - 15]   ,   18						)
							    ^ (words[index - 15] >> 3)
							)
							SCREAMING_SNAKE_CASE :   Union[str, Any]					  =							(
							    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
							) % 0x100_000_000

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

						SCREAMING_SNAKE_CASE  ,SCREAMING_SNAKE_CASE  ,SCREAMING_SNAKE_CASE  ,SCREAMING_SNAKE_CASE  ,SCREAMING_SNAKE_CASE  ,SCREAMING_SNAKE_CASE  ,SCREAMING_SNAKE_CASE  ,SCREAMING_SNAKE_CASE :   Dict					  =							(
						    g,
						    f,
						    e,
						    ((d + tempa) % 0x100_000_000),
						    c,
						    b,
						    a,
						    ((tempa + tempa) % 0x100_000_000),
						)

					SCREAMING_SNAKE_CASE :   Optional[Any]					  =							[a, b, c, d, e, f, g, h]

					# Modify final values
					SCREAMING_SNAKE_CASE :   Tuple					  =							[
					    ((element + mutated_hash_values[index]) % 0x100_000_000)
					    for index, element in enumerate(self.hashes						)
					]

				SCREAMING_SNAKE_CASE :   int					  =							"".join([hex(a						)[2:].zfill(8						) for value in self.hashes]						)






			def 				__UpperCamelCase			(      self				:			List[str]   ,   a				:			int   ,   a				:			int						)				->							int:

				"""simple docstring"""

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






class _UpperCamelCase				(				unittest.TestCase ):
			'''simple docstring'''







			def 				__UpperCamelCase			(      self				:			Optional[Any]						)				->							None:

				"""simple docstring"""

				import hashlib

				SCREAMING_SNAKE_CASE :   Tuple					  =							bytes("Test String"   ,   "utf-8"						)
				self.assertEqual(SHAaaa(a						).hash   ,   hashlib.shaaaa(a						).hexdigest()						)

def 			lowerCamelCase__			(       ):
	import doctest

	doctest.testmod()

	SCREAMING_SNAKE_CASE :   Tuple					  =							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 :   Union[str, Any]					  =							parser.parse_args()

	SCREAMING_SNAKE_CASE :   int					  =							args.input_string

	# hash input should be a bytestring
	if args.input_file:
		with open(args.input_file				,      "rb") as f:
			SCREAMING_SNAKE_CASE :   Optional[int]					  =							f.read()
	else:
		SCREAMING_SNAKE_CASE :   List[Any]					  =							bytes(_a				,      "utf-8")

	print(SHAaaa(_a).hash)


if __name__ == "__main__":
			main()


import gc
import unittest

import numpy as np
import torch

from diffusers import StableDiffusionKDiffusionPipeline
from diffusers.utils import slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, require_torch_gpu


enable_full_determinism()






@slow
@require_torch_gpu
class _UpperCamelCase				(				unittest.TestCase ):
			'''simple docstring'''







			def 				__UpperCamelCase			(      self				:			Dict						)				->							Tuple:

				"""simple docstring"""

				super().tearDown()
				gc.collect()
				torch.cuda.empty_cache()
			def 				__UpperCamelCase			(      self				:			Optional[int]						)				->							int:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE :   Optional[Any]					  =							StableDiffusionKDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4"						)
				SCREAMING_SNAKE_CASE :   str					  =							sd_pipe.to(a						)
				sd_pipe.set_progress_bar_config(disable=a						)

				sd_pipe.set_scheduler("sample_euler"						)

				SCREAMING_SNAKE_CASE :   Optional[int]					  =							"A painting of a squirrel eating a burger"
				SCREAMING_SNAKE_CASE :   Any					  =							torch.manual_seed(0						)
				SCREAMING_SNAKE_CASE :   List[Any]					  =							sd_pipe([prompt]   ,   generator=a   ,   guidance_scale=9.0   ,   num_inference_steps=20   ,   output_type="np"						)

				SCREAMING_SNAKE_CASE :   Tuple					  =							output.images

				SCREAMING_SNAKE_CASE :   Any					  =							image[0, -3:, -3:, -1]

				assert image.shape == (1, 512, 512, 3)
				SCREAMING_SNAKE_CASE :   Union[str, Any]					  =							np.array([0.0447, 0.0492, 0.0468, 0.0408, 0.0383, 0.0408, 0.0354, 0.0380, 0.0339]						)

				assert np.abs(image_slice.flatten() - expected_slice						).max() < 1e-2
			def 				__UpperCamelCase			(      self				:			List[Any]						)				->							Optional[int]:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE :   int					  =							StableDiffusionKDiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-2-1-base"						)
				SCREAMING_SNAKE_CASE :   Tuple					  =							sd_pipe.to(a						)
				sd_pipe.set_progress_bar_config(disable=a						)

				sd_pipe.set_scheduler("sample_euler"						)

				SCREAMING_SNAKE_CASE :   List[str]					  =							"A painting of a squirrel eating a burger"
				SCREAMING_SNAKE_CASE :   List[str]					  =							torch.manual_seed(0						)
				SCREAMING_SNAKE_CASE :   Union[str, Any]					  =							sd_pipe([prompt]   ,   generator=a   ,   guidance_scale=9.0   ,   num_inference_steps=20   ,   output_type="np"						)

				SCREAMING_SNAKE_CASE :   List[Any]					  =							output.images

				SCREAMING_SNAKE_CASE :   Tuple					  =							image[0, -3:, -3:, -1]

				assert image.shape == (1, 512, 512, 3)
				SCREAMING_SNAKE_CASE :   int					  =							np.array([0.1237, 0.1320, 0.1438, 0.1359, 0.1390, 0.1132, 0.1277, 0.1175, 0.1112]						)

				assert np.abs(image_slice.flatten() - expected_slice						).max() < 5e-1






			def 				__UpperCamelCase			(      self				:			Tuple						)				->							List[Any]:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE :   Dict					  =							StableDiffusionKDiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-2-1-base"						)
				SCREAMING_SNAKE_CASE :   Union[str, Any]					  =							sd_pipe.to(a						)
				sd_pipe.set_progress_bar_config(disable=a						)

				sd_pipe.set_scheduler("sample_dpmpp_2m"						)

				SCREAMING_SNAKE_CASE :   str					  =							"A painting of a squirrel eating a burger"
				SCREAMING_SNAKE_CASE :   Any					  =							torch.manual_seed(0						)
				SCREAMING_SNAKE_CASE :   str					  =							sd_pipe(
				    [prompt]   ,   generator=a   ,   guidance_scale=7.5   ,   num_inference_steps=15   ,   output_type="np"   ,   use_karras_sigmas=a   ,   )

				SCREAMING_SNAKE_CASE :   str					  =							output.images

				SCREAMING_SNAKE_CASE :   Optional[int]					  =							image[0, -3:, -3:, -1]

				assert image.shape == (1, 512, 512, 3)
				SCREAMING_SNAKE_CASE :   int					  =							np.array(
				    [0.1138_1689, 0.1211_2921, 0.138_9457, 0.1254_9606, 0.124_4964, 0.1083_1517, 0.1156_2866, 0.1086_7816, 0.1049_9048]						)

				assert np.abs(image_slice.flatten() - expected_slice						).max() < 1e-2