


import argparse
import struct
import unittest



class 							A   :
					'''simple docstring'''






					def __init__(self   :						Any				, _UpperCAmelCase   :						int		)						->       Any:




							"""simple docstring"""


							lowercase__					      =		data

							# Initialize hash values
							lowercase__					      =		[
							    0x6a09e667,
							    0xbb67ae85,
							    0x3c6ef372,
							    0xa54ff53a,
							    0x510e527f,
							    0x9b05688c,
							    0x1f83d9ab,
							    0x5be0cd19,
							]

							# Initialize round constants
							lowercase__					      =		[
							    0x428a2f98,
							    0x71374491,
							    0xb5c0fbcf,
							    0xe9b5dba5,
							    0x3956c25b,
							    0x59f111f1,
							    0x923f82a4,
							    0xab1c5ed5,
							    0xd807aa98,
							    0x12835b01,
							    0x243185be,
							    0x550c7dc3,
							    0x72be5d74,
							    0x80deb1fe,
							    0x9bdc06a7,
							    0xc19bf174,
							    0xe49b69c1,
							    0xefbe4786,
							    0x0fc19dc6,
							    0x240ca1cc,
							    0x2de92c6f,
							    0x4a7484aa,
							    0x5cb0a9dc,
							    0x76f988da,
							    0x983e5152,
							    0xa831c66d,
							    0xb00327c8,
							    0xbf597fc7,
							    0xc6e00bf3,
							    0xd5a79147,
							    0x06ca6351,
							    0x14292967,
							    0x27b70a85,
							    0x2e1b2138,
							    0x4d2c6dfc,
							    0x53380d13,
							    0x650a7354,
							    0x766a0abb,
							    0x81c2c92e,
							    0x92722c85,
							    0xa2bfe8a1,
							    0xa81a664b,
							    0xc24b8b70,
							    0xc76c51a3,
							    0xd192e819,
							    0xd6990624,
							    0xf40e3585,
							    0x106aa070,
							    0x19a4c116,
							    0x1e376c08,
							    0x2748774c,
							    0x34b0bcb5,
							    0x391c0cb3,
							    0x4ed8aa4a,
							    0x5b9cca4f,
							    0x682e6ff3,
							    0x748f82ee,
							    0x78a5636f,
							    0x84c87814,
							    0x8cc70208,
							    0x90befffa,
							    0xa4506ceb,
							    0xbef9a3f7,
							    0xc67178f2,
							]

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

					@staticmethod
					def   lowerCamelCase__					(_UpperCAmelCase   :						Any		)						->       Any:




							"""simple docstring"""


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

					def   lowerCamelCase__					(self   :						List[Any]		)						->       List[Any]:




							"""simple docstring"""


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

									lowercase__      ,     lowercase__      ,     lowercase__      ,     lowercase__      ,     lowercase__      ,     lowercase__      ,     lowercase__      ,     lowercase__					      =		self.hashes

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

													lowercase__					      =		(
													    words[index - 16] + sa + words[index - 7] + sa
													) % 0x100000000

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

											lowercase__      ,     lowercase__      ,     lowercase__      ,     lowercase__      ,     lowercase__      ,     lowercase__      ,     lowercase__      ,     lowercase__					      =		(
											    g,
											    f,
											    e,
											    ((d + tempa) % 0x100000000),
											    c,
											    b,
											    a,
											    ((tempa + tempa) % 0x100000000),
											)

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

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

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


					def   lowerCamelCase__					(self   :						str				, _UpperCAmelCase   :						Optional[int]				, _UpperCAmelCase   :						List[str]		)						->       Optional[int]:




							"""simple docstring"""


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






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






					def   lowerCamelCase__					(self   :						str		)						->       Union[str, Any]:




							"""simple docstring"""


							import hashlib

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






def 			UpperCamelCase (     ):
		"""simple docstring"""




		import doctest

		doctest.testmod()

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

		lowercase__					      =		parser.parse_args()

		lowercase__					      =		args.input_string

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

		print(SHAaaa(lowercase_					).hash					)


if __name__ == "__main__":
	main()





from __future__ import annotations

from collections import deque



class 							A   :
					'''simple docstring'''






					def __init__(self   :						Any				, _UpperCAmelCase   :						list[str]		)						->       Optional[int]:




							"""simple docstring"""


							lowercase__					      =		[]
							self.adlist.append(
							    {"""value""": """""", """next_states""": [], """fail_state""": 0, """output""": []}		)

							for keyword in keywords:
									self.add_keyword(_UpperCAmelCase		)
							self.set_fail_transitions()

					def   lowerCamelCase__					(self   :						List[str]				, _UpperCAmelCase   :						int				, _UpperCAmelCase   :						str		)						->       int | None:




							"""simple docstring"""


							for state in self.adlist[current_state]["next_states"]:
									if char == self.adlist[state]["value"]:
											return state
							return None

					def   lowerCamelCase__					(self   :						List[Any]				, _UpperCAmelCase   :						str		)						->       None:




							"""simple docstring"""


							lowercase__					      =		0
							for character in keyword:
									lowercase__					      =		self.find_next_state(_UpperCAmelCase				, _UpperCAmelCase		)
									if next_state is None:
											self.adlist.append(
											    {
											        """value""": character,
											        """next_states""": [],
											        """fail_state""": 0,
											        """output""": [],
											    }		)
											self.adlist[current_state]["next_states"].append(len(self.adlist		) - 1		)
											lowercase__					      =		len(self.adlist		) - 1
									else:
											lowercase__					      =		next_state
							self.adlist[current_state]["output"].append(_UpperCAmelCase		)

					def   lowerCamelCase__					(self   :						Any		)						->       None:




							"""simple docstring"""


							lowercase__					      =		deque()
							for node in self.adlist[0]["next_states"]:
									q.append(_UpperCAmelCase		)
									lowercase__					      =		0
							while q:
									lowercase__					      =		q.popleft()
									for child in self.adlist[r]["next_states"]:
											q.append(_UpperCAmelCase		)
											lowercase__					      =		self.adlist[r]["""fail_state"""]
											while (
											    self.find_next_state(_UpperCAmelCase				, self.adlist[child]["""value"""]		) is None
											    and state != 0
											):
													lowercase__					      =		self.adlist[state]["""fail_state"""]
											lowercase__					      =		self.find_next_state(
											    _UpperCAmelCase				, self.adlist[child]["""value"""]		)
											if self.adlist[child]["fail_state"] is None:
													lowercase__					      =		0
											lowercase__					      =		(
											    self.adlist[child]["""output"""]
											    + self.adlist[self.adlist[child]["""fail_state"""]]["""output"""]
											)


					def   lowerCamelCase__					(self   :						List[str]				, _UpperCAmelCase   :						str		)						->       dict[str, list[int]]:




							"""simple docstring"""


							lowercase__					      =		{}  # returns a dict with keywords and list of its occurrences
							lowercase__					      =		0
							for i in range(len(_UpperCAmelCase		)		):
									while (
									    self.find_next_state(_UpperCAmelCase				, string[i]		) is None
									    and current_state != 0
									):
											lowercase__					      =		self.adlist[current_state]["""fail_state"""]
									lowercase__					      =		self.find_next_state(_UpperCAmelCase				, string[i]		)
									if next_state is None:
											lowercase__					      =		0
									else:
											lowercase__					      =		next_state
											for key in self.adlist[current_state]["output"]:
													if key not in result:
															lowercase__					      =		[]
													result[key].append(i - len(_UpperCAmelCase		) + 1		)
							return result


if __name__ == "__main__":
	import doctest

	doctest.testmod()

