


import argparse
import struct
import unittest







class        __lowercase       :



		"""simple docstring"""

		def __init__( self		,      A	)  -> None:







					'''simple docstring'''







					lowerCamelCase    		=  data

					# Initialize hash values
					lowerCamelCase    		=  [
					    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
					lowerCamelCase    		=  [
					    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,
					]

					lowerCamelCase    		=  self.preprocessing(self.data	)
					self.final_hash()







		@staticmethod
		def 					__A   ( A	)  -> bytes:







					'''simple docstring'''







					lowerCamelCase    		=  B"""\x80""" + (B"""\x00""" * (63 - (len(A	) + 8) % 64))
					lowerCamelCase    		=  struct.pack(""">Q"""		,      (len(A	) * 8)	)
					return data + padding + big_endian_integer







		def 					__A   ( self	)  -> None:







					'''simple docstring'''







					lowerCamelCase    		=  [
					    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
								lowerCamelCase    		=  list(struct.unpack(""">16L"""		,      A	)	)
								# add 48 0-ed integers
								words += [0] * 48

								lowerCamelCase		,		lowerCamelCase		,		lowerCamelCase		,		lowerCamelCase		,		lowerCamelCase		,		lowerCamelCase		,		lowerCamelCase		,		lowerCamelCase    		=  self.hashes

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

														lowerCamelCase    		=  (
														    words[index - 16] + sa + words[index - 7] + sa
														) % 0x100_000_000

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

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

								lowerCamelCase    		=  [a, b, c, d, e, f, g, h]

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

					lowerCamelCase    		=  """""".join([hex(A	)[2:].zfill(8	) for value in self.hashes]	)







		def 					__A   ( self		,      A		,      A	)  -> int:







					'''simple docstring'''







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







class        __lowercase       (							unittest.TestCase  ):



		"""simple docstring"""

		def 					__A   ( self	)  -> None:







					'''simple docstring'''







					import hashlib

					lowerCamelCase    		=  bytes("""Test String"""		,      """utf-8"""	)
					self.assertEqual(SHAaaa(A	).hash		,      hashlib.shaaaa(A	).hexdigest()	)






def 	__lowerCamelCase						(							):





			'''simple docstring'''




			import doctest

			doctest.testmod()

			lowerCamelCase    		=  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"""      )

			lowerCamelCase    		=  parser.parse_args()

			lowerCamelCase    		=  args.input_string

			# hash input should be a bytestring
			if args.input_file:
						with open(args.input_file  ,							"""rb"""      ) as f:
									lowerCamelCase    		=  f.read()
			else:
						lowerCamelCase    		=  bytes(lowerCamelCase__  ,							"""utf-8"""      )

			print(SHAaaa(lowerCamelCase__      ).hash      )


if __name__ == "__main__":
		main()





import math

import tensorflow as tf
from packaging import version






def 	__lowerCamelCase						(							lowerCamelCase__		:						Any      ):





			'''simple docstring'''




			lowerCamelCase    		=  tf.convert_to_tensor(lowerCamelCase__      )
			lowerCamelCase    		=  0.5 * (1.0 + tf.math.erf(x / tf.cast(tf.sqrt(2.0      )  ,							x.dtype      )      ))

			return x * cdf






def 	__lowerCamelCase						(							lowerCamelCase__		:						List[str]      ):





			'''simple docstring'''




			lowerCamelCase    		=  tf.convert_to_tensor(lowerCamelCase__      )
			lowerCamelCase    		=  tf.cast(math.pi  ,							x.dtype      )
			lowerCamelCase    		=  tf.cast(0.0_4_4_7_1_5  ,							x.dtype      )
			lowerCamelCase    		=  0.5 * (1.0 + tf.tanh(tf.sqrt(2.0 / pi      ) * (x + coeff * tf.pow(lowerCamelCase__  ,							3      ))      ))

			return x * cdf






def 	__lowerCamelCase						(							lowerCamelCase__		:						int      ):





			'''simple docstring'''




			lowerCamelCase    		=  tf.convert_to_tensor(lowerCamelCase__      )

			return x * tf.tanh(tf.math.softplus(lowerCamelCase__      )      )






def 	__lowerCamelCase						(							lowerCamelCase__		:						Union[str, Any]      ):





			'''simple docstring'''




			lowerCamelCase    		=  tf.convert_to_tensor(lowerCamelCase__      )
			lowerCamelCase    		=  tf.cast(0.0_4_4_7_1_5  ,							x.dtype      )
			lowerCamelCase    		=  tf.cast(0.7_9_7_8_8_4_5_6_0_8  ,							x.dtype      )

			return 0.5 * x * (1.0 + tf.tanh(x * coeffa * (1.0 + coeffa * x * x)      ))






def 	__lowerCamelCase						(							lowerCamelCase__		:						Optional[int]      ):





			'''simple docstring'''




			lowerCamelCase    		=  tf.convert_to_tensor(lowerCamelCase__      )
			lowerCamelCase    		=  tf.cast(1.7_0_2  ,							x.dtype      )
			return x * tf.math.sigmoid(coeff * x      )






def 	__lowerCamelCase						(							lowerCamelCase__		:						Dict      ):





			'''simple docstring'''




			return tf.clip_by_value(_gelu(lowerCamelCase__      )  ,							-10  ,							10      )






def 	__lowerCamelCase						(							lowerCamelCase__		:						int  ,							lowerCamelCase__		:						Dict=-1      ):





			'''simple docstring'''




			lowerCamelCase		,		lowerCamelCase    		=  tf.split(lowerCamelCase__  ,							2  ,							axis=lowerCamelCase__      )
			return a * tf.math.sigmoid(lowerCamelCase__      )


if version.parse(tf.version.VERSION) >= version.parse("2.4"):






		def 	__lowerCamelCase						(							lowerCamelCase__		:						Union[str, Any]      ):





					'''simple docstring'''




					return tf.keras.activations.gelu(lowerCamelCase__  ,							approximate=lowerCamelCase__      )

		UpperCAmelCase   :    Union[str, Any]     =		tf.keras.activations.gelu



		UpperCAmelCase   :    int     =		approximate_gelu_wrap
else:
		UpperCAmelCase   :    Dict     =		_gelu
		UpperCAmelCase   :    Dict     =		_gelu_new


UpperCAmelCase   :    List[str]     =		{
    "gelu": gelu,
    "gelu_10": gelu_aa,
    "gelu_fast": gelu_fast,
    "gelu_new": gelu_new,
    "glu": glu,
    "mish": mish,
    "quick_gelu": quick_gelu,
    "relu": tf.keras.activations.relu,
    "sigmoid": tf.keras.activations.sigmoid,
    "silu": tf.keras.activations.swish,
    "swish": tf.keras.activations.swish,
    "tanh": tf.keras.activations.tanh,
}






def 	__lowerCamelCase						(							lowerCamelCase__		:						Tuple      ):





			'''simple docstring'''




			if activation_string in ACTaFN:
						return ACTaFN[activation_string]
			else:
						raise KeyError(f'function {activation_string} not found in ACT2FN mapping {list(ACTaFN.keys()      )}'      )

