from collections.abc import Generator
from math import sin
def 					_snake_case	(  __snake_case						):
					if len(__snake_case						) != 32:
										raise ValueError('''Input must be of length 32'''						)

					_UpperCamelCase			     =     B''''''
					for i in [3, 2, 1, 0]:
										little_endian += string_aa[8 * i : 8 * i + 8]
					return little_endian
def 					_snake_case	(  __snake_case						):
					if i < 0:
										raise ValueError('''Input must be non-negative'''						)

					_UpperCamelCase			     =     format(__snake_case  ,     '''08x'''						)[-8:]
					_UpperCamelCase			     =     B''''''
					for i in [3, 2, 1, 0]:
										little_endian_hex += hex_rep[2 * i : 2 * i + 2].encode('''utf-8'''						)
					return little_endian_hex
def 					_snake_case	(  __snake_case						):
					_UpperCamelCase			     =     B''''''
					for char in message:
										bit_string += format(__snake_case  ,     '''08b'''						).encode('''utf-8'''						)
					_UpperCamelCase			     =     format(len(__snake_case						)  ,     '''064b'''						).encode('''utf-8'''						)

					# Pad bit_string to a multiple of 512 chars
					bit_string += b"1"
					while len(__snake_case						) % 512 != 448:
										bit_string += b"0"
					bit_string += to_little_endian(start_len[32:]						) + to_little_endian(start_len[:32]						)

					return bit_string
def 					_snake_case	(  __snake_case						):
					if len(__snake_case						) % 512 != 0:
										raise ValueError('''Input must have length that\'s a multiple of 512'''						)

					for pos in range(0  ,     len(__snake_case						)  ,     512						):
										_UpperCamelCase			     =     bit_string[pos : pos + 512]
										_UpperCamelCase			     =     []
										for i in range(0  ,     512  ,     32						):
															block_words.append(int(to_little_endian(block[i : i + 32]						)  ,     2						)						)
										yield block_words
def 					_snake_case	(  __snake_case						):
					if i < 0:
										raise ValueError('''Input must be non-negative'''						)

					_UpperCamelCase			     =     format(__snake_case  ,     '''032b'''						)
					_UpperCamelCase			     =     ''''''
					for c in i_str:
										new_str += "1" if c == "0" else "0"
					return int(__snake_case  ,     2						)
def 					_snake_case	(  __snake_case  ,     __snake_case						):
					return (a + b) % 2**32
def 					_snake_case	(  __snake_case  ,     __snake_case						):
					if i < 0:
										raise ValueError('''Input must be non-negative'''						)
					if shift < 0:
										raise ValueError('''Shift must be non-negative'''						)
					return ((i << shift) ^ (i >> (32 - shift))) % 2**32
def 					_snake_case	(  __snake_case						):
					_UpperCamelCase			     =     preprocess(__snake_case						)

					_UpperCamelCase			     =     [int(2**32 * abs(sin(i + 1						)						)						) for i in range(64						)]

					# Starting states
					_UpperCamelCase			     =     0x6745_2301
					_UpperCamelCase			     =     0xEFCD_AB89
					_UpperCamelCase			     =     0x98BA_DCFE
					_UpperCamelCase			     =     0x1032_5476

					_UpperCamelCase			     =     [
					    7,
					    12,
					    17,
					    22,
					    7,
					    12,
					    17,
					    22,
					    7,
					    12,
					    17,
					    22,
					    7,
					    12,
					    17,
					    22,
					    5,
					    9,
					    14,
					    20,
					    5,
					    9,
					    14,
					    20,
					    5,
					    9,
					    14,
					    20,
					    5,
					    9,
					    14,
					    20,
					    4,
					    11,
					    16,
					    23,
					    4,
					    11,
					    16,
					    23,
					    4,
					    11,
					    16,
					    23,
					    4,
					    11,
					    16,
					    23,
					    6,
					    10,
					    15,
					    21,
					    6,
					    10,
					    15,
					    21,
					    6,
					    10,
					    15,
					    21,
					    6,
					    10,
					    15,
					    21,
					]

					# Process bit string in chunks, each with 16 32-char words
					for block_words in get_block_words(__snake_case						):
										_UpperCamelCase			     =     aa
										_UpperCamelCase			     =     ba
										_UpperCamelCase			     =     ca
										_UpperCamelCase			     =     da

										# Hash current chunk
										for i in range(64						):
															if i <= 15:
																				# f = (b & c) | (not_32(b) & d)     # Alternate definition for f
																				_UpperCamelCase			     =     d ^ (b & (c ^ d))
																				_UpperCamelCase			     =     i
															elif i <= 31:
																				# f = (d & b) | (not_32(d) & c)     # Alternate definition for f
																				_UpperCamelCase			     =     c ^ (d & (b ^ c))
																				_UpperCamelCase			     =     (5 * i + 1) % 16
															elif i <= 47:
																				_UpperCamelCase			     =     b ^ c ^ d
																				_UpperCamelCase			     =     (3 * i + 5) % 16
															else:
																				_UpperCamelCase			     =     c ^ (b | not_aa(__snake_case						))
																				_UpperCamelCase			     =     (7 * i) % 16
															_UpperCamelCase			     =     (f + a + added_consts[i] + block_words[g]) % 2**32
															_UpperCamelCase			     =     d
															_UpperCamelCase			     =     c
															_UpperCamelCase			     =     b
															_UpperCamelCase			     =     sum_aa(__snake_case  ,     left_rotate_aa(__snake_case  ,     shift_amounts[i]						)						)

										# Add hashed chunk to running total
										_UpperCamelCase			     =     sum_aa(__snake_case  ,     __snake_case						)
										_UpperCamelCase			     =     sum_aa(__snake_case  ,     __snake_case						)
										_UpperCamelCase			     =     sum_aa(__snake_case  ,     __snake_case						)
										_UpperCamelCase			     =     sum_aa(__snake_case  ,     __snake_case						)

					_UpperCamelCase			     =     reformat_hex(__snake_case						) + reformat_hex(__snake_case						) + reformat_hex(__snake_case						) + reformat_hex(__snake_case						)
					return digest


if __name__ == "__main__":
					import doctest

					doctest.testmod()







import argparse
import struct
import unittest


class        __magic_name__	:





     """simple docstring"""



     def __init__(				self							:str      ,   snake_case							:bytes	):





        '''simple docstring'''




        A_       :					Dict        =      data

        # Initialize hash values
        A_       :					Union[str, Any]        =      [
            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
        A_       :					List[Any]        =      [
            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,
        ]

        A_       :					Any        =      self.preprocessing(self.data	)
        self.final_hash()



     @staticmethod
     def     SCREAMING_SNAKE_CASE		(				snake_case							:bytes	):





        '''simple docstring'''




        A_       :					List[Any]        =      B"\x80" + (B"\x00" * (63 - (len(snake_case	) + 8) % 64))
        A_       :					str        =      struct.pack(">Q"      ,   (len(snake_case	) * 8)	)
        return data + padding + big_endian_integer



     def     SCREAMING_SNAKE_CASE		(				self							:Any	):





        '''simple docstring'''




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

           A_   ,    A_   ,    A_   ,    A_   ,    A_   ,    A_   ,    A_   ,    A_       :					int        =      self.hashes

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

                 A_       :					Optional[int]        =      (
                     words[index - 16] + sa + words[index - 7] + sa
                 ) % 0x1_00_00_00_00

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

              A_   ,    A_   ,    A_   ,    A_   ,    A_   ,    A_   ,    A_   ,    A_       :					Optional[int]        =      (
                  g,
                  f,
                  e,
                  ((d + tempa) % 0x1_00_00_00_00),
                  c,
                  b,
                  a,
                  ((tempa + tempa) % 0x1_00_00_00_00),
              )

           A_       :					List[str]        =      [a, b, c, d, e, f, g, h]

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

        A_       :					Optional[int]        =      "".join([hex(snake_case	)[2:].zfill(8	) for value in self.hashes]	)





     def     SCREAMING_SNAKE_CASE		(				self							:Optional[Any]      ,   snake_case							:int      ,   snake_case							:int	):





        '''simple docstring'''




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




class        __magic_name__	(				unittest.TestCase				):





     """simple docstring"""



     def     SCREAMING_SNAKE_CASE		(				self							:List[Any]	):





        '''simple docstring'''




        import hashlib

        A_       :					int        =      bytes("Test String"      ,   "utf-8"	)
        self.assertEqual(SHAaaa(snake_case	).hash      ,   hashlib.shaaaa(snake_case	).hexdigest()	)




def   __snake_case    (       )			->    None:
   import doctest

   doctest.testmod()

   A_       :					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"						)

   A_       :					List[Any]        =      parser.parse_args()

   A_       :					List[Any]        =      args.input_string

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

   print(SHAaaa(_lowerCAmelCase						).hash						)


if __name__ == "__main__":
 main()
