






from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_tf_available,
    is_torch_available,
    is_vision_available,
)


UpperCAmelCase__				   =		{
    "configuration_mobilevit": ["MOBILEVIT_PRETRAINED_CONFIG_ARCHIVE_MAP", "MobileViTConfig", "MobileViTOnnxConfig"],
}

try:
     if not is_vision_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     pass
else:
     UpperCAmelCase__				   =		["MobileViTFeatureExtractor"]
     UpperCAmelCase__				   =		["MobileViTImageProcessor"]

try:
     if not is_torch_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     pass
else:
     UpperCAmelCase__				   =		[
         "MOBILEVIT_PRETRAINED_MODEL_ARCHIVE_LIST",
         "MobileViTForImageClassification",
         "MobileViTForSemanticSegmentation",
         "MobileViTModel",
         "MobileViTPreTrainedModel",
     ]

try:
     if not is_tf_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     pass
else:
     UpperCAmelCase__				   =		[
         "TF_MOBILEVIT_PRETRAINED_MODEL_ARCHIVE_LIST",
         "TFMobileViTForImageClassification",
         "TFMobileViTForSemanticSegmentation",
         "TFMobileViTModel",
         "TFMobileViTPreTrainedModel",
     ]

if TYPE_CHECKING:
     from .configuration_mobilevit import MOBILEVIT_PRETRAINED_CONFIG_ARCHIVE_MAP, MobileViTConfig, MobileViTOnnxConfig

     try:
          if not is_vision_available():
               raise OptionalDependencyNotAvailable()
     except OptionalDependencyNotAvailable:
          pass
     else:
          from .feature_extraction_mobilevit import MobileViTFeatureExtractor
          from .image_processing_mobilevit import MobileViTImageProcessor

     try:
          if not is_torch_available():
               raise OptionalDependencyNotAvailable()
     except OptionalDependencyNotAvailable:
          pass
     else:
          from .modeling_mobilevit import (
              MOBILEVIT_PRETRAINED_MODEL_ARCHIVE_LIST,
              MobileViTForImageClassification,
              MobileViTForSemanticSegmentation,
              MobileViTModel,
              MobileViTPreTrainedModel,
          )

     try:
          if not is_tf_available():
               raise OptionalDependencyNotAvailable()
     except OptionalDependencyNotAvailable:
          pass
     else:
          from .modeling_tf_mobilevit import (
              TF_MOBILEVIT_PRETRAINED_MODEL_ARCHIVE_LIST,
              TFMobileViTForImageClassification,
              TFMobileViTForSemanticSegmentation,
              TFMobileViTModel,
              TFMobileViTPreTrainedModel,
          )


else:
     import sys

     UpperCAmelCase__				   =		_LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)






'''simple docstring'''


import argparse
import struct
import unittest





class     lowercase__  :





							'''simple docstring'''


							def __init__(    self    ,					__snake_case  ):
											_SCREAMING_SNAKE_CASE :       Dict     		=      data

											# Initialize hash values
											_SCREAMING_SNAKE_CASE :       Tuple     		=      [
											    0X6A09_E667,
											    0XBB67_AE85,
											    0X3C6E_F372,
											    0XA54F_F53A,
											    0X510E_527F,
											    0X9B05_688C,
											    0X1F83_D9AB,
											    0X5BE0_CD19,
											]

											# Initialize round constants
											_SCREAMING_SNAKE_CASE :       int     		=      [
											    0X428A_2F98,
											    0X7137_4491,
											    0XB5C0_FBCF,
											    0XE9B5_DBA5,
											    0X3956_C25B,
											    0X59F1_11F1,
											    0X923F_82A4,
											    0XAB1C_5ED5,
											    0XD807_AA98,
											    0X1283_5B01,
											    0X2431_85BE,
											    0X550C_7DC3,
											    0X72BE_5D74,
											    0X80DE_B1FE,
											    0X9BDC_06A7,
											    0XC19B_F174,
											    0XE49B_69C1,
											    0XEFBE_4786,
											    0X0FC1_9DC6,
											    0X240C_A1CC,
											    0X2DE9_2C6F,
											    0X4A74_84AA,
											    0X5CB0_A9DC,
											    0X76F9_88DA,
											    0X983E_5152,
											    0XA831_C66D,
											    0XB003_27C8,
											    0XBF59_7FC7,
											    0XC6E0_0BF3,
											    0XD5A7_9147,
											    0X06CA_6351,
											    0X1429_2967,
											    0X27B7_0A85,
											    0X2E1B_2138,
											    0X4D2C_6DFC,
											    0X5338_0D13,
											    0X650A_7354,
											    0X766A_0ABB,
											    0X81C2_C92E,
											    0X9272_2C85,
											    0XA2BF_E8A1,
											    0XA81A_664B,
											    0XC24B_8B70,
											    0XC76C_51A3,
											    0XD192_E819,
											    0XD699_0624,
											    0XF40E_3585,
											    0X106A_A070,
											    0X19A4_C116,
											    0X1E37_6C08,
											    0X2748_774C,
											    0X34B0_BCB5,
											    0X391C_0CB3,
											    0X4ED8_AA4A,
											    0X5B9C_CA4F,
											    0X682E_6FF3,
											    0X748F_82EE,
											    0X78A5_636F,
											    0X84C8_7814,
											    0X8CC7_0208,
											    0X90BE_FFFA,
											    0XA450_6CEB,
											    0XBEF9_A3F7,
											    0XC671_78F2,
											]

											_SCREAMING_SNAKE_CASE :       Optional[int]     		=      self.preprocessing(self.data  )
											self.final_hash()






							@staticmethod
							def UpperCAmelCase_	(    __snake_case  ):
											_SCREAMING_SNAKE_CASE :       Tuple     		=      B"""\x80""" + (B"""\x00""" * (63 - (len(__snake_case  ) + 8) % 64))
											_SCREAMING_SNAKE_CASE :       List[str]     		=      struct.pack(""">Q"""    ,					(len(__snake_case  ) * 8)  )
											return data + padding + big_endian_integer






							def UpperCAmelCase_	(    self  ):
											# Convert into blocks of 64 bytes
											_SCREAMING_SNAKE_CASE :       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 :       List[Any]     		=      list(struct.unpack(""">16L"""    ,					__snake_case  )  )
															# 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 :       Optional[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 :       Optional[Any]     		=      (
																							    self.ror(words[index - 15]    ,					7  )
																							    ^ self.ror(words[index - 15]    ,					18  )
																							    ^ (words[index - 15] >> 3)
																							)
																							_SCREAMING_SNAKE_CASE :       Tuple     		=      (
																							    self.ror(words[index - 2]    ,					17  )
																							    ^ self.ror(words[index - 2]    ,					19  )
																							    ^ (words[index - 2] >> 10)
																							)

																							_SCREAMING_SNAKE_CASE :       Tuple     		=      (
																							    words[index - 16] + sa + words[index - 7] + sa
																							) % 0X1_0000_0000

																			# Compression
																			_SCREAMING_SNAKE_CASE :       Any     		=      self.ror(__snake_case    ,					6  ) ^ self.ror(__snake_case    ,					11  ) ^ self.ror(__snake_case    ,					25  )
																			_SCREAMING_SNAKE_CASE :       str     		=      (e & f) ^ ((~e & 0XFFFF_FFFF) & g)
																			_SCREAMING_SNAKE_CASE :       str     		=      (
																			    h + sa + ch + self.round_constants[index] + words[index]
																			) % 0X1_0000_0000
																			_SCREAMING_SNAKE_CASE :       Dict     		=      self.ror(__snake_case    ,					2  ) ^ self.ror(__snake_case    ,					13  ) ^ self.ror(__snake_case    ,					22  )
																			_SCREAMING_SNAKE_CASE :       Union[str, Any]     		=      (a & b) ^ (a & c) ^ (b & c)
																			_SCREAMING_SNAKE_CASE :       Dict     		=      (sa + maj) % 0X1_0000_0000

																			_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) % 0X1_0000_0000),
																			    c,
																			    b,
																			    a,
																			    ((tempa + tempa) % 0X1_0000_0000),
																			)

															_SCREAMING_SNAKE_CASE :       Union[str, Any]     		=      [a, b, c, d, e, f, g, h]

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

											_SCREAMING_SNAKE_CASE :       Dict     		=      """""".join([hex(__snake_case  )[2:].zfill(8  ) for value in self.hashes]  )






							def UpperCAmelCase_	(    self    ,					__snake_case    ,					__snake_case  ):
											return 0XFFFF_FFFF & (value << (32 - rotations)) | (value >> rotations)





class     lowercase__  (						unittest.TestCase					):





							'''simple docstring'''


							def UpperCAmelCase_	(    self  ):
											import hashlib

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







def 			snake_case_   (  ):







				"""simple docstring"""





				import doctest

				doctest.testmod()

				_SCREAMING_SNAKE_CASE :       Optional[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 :       Dict     		=      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 :       str     		=      f.read()
				else:
								_SCREAMING_SNAKE_CASE :       List[Any]     		=      bytes(SCREAMING_SNAKE_CASE__							,      """utf-8"""     )

				print(SHAaaa(SCREAMING_SNAKE_CASE__     ).hash     )


if __name__ == "__main__":
				main()




