


import argparse
import struct
import unittest






class 							UpperCamelCase					:


   '''simple docstring'''







   def __init__(     self   ,							UpperCamelCase_		):
        lowercase_       :Any     =       data

        # Initialize hash values
        lowercase_       :Optional[int]     =       [
            0X6A09E667,
            0XBB67AE85,
            0X3C6EF372,
            0XA54FF53A,
            0X510E527F,
            0X9B05688C,
            0X1F83D9AB,
            0X5BE0CD19,
        ]

        # Initialize round constants
        lowercase_       :Any     =       [
            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_       :Optional[int]     =       self.preprocessing(self.data		)
        self.final_hash()
   @staticmethod
   def 		UpperCamelCase  (     UpperCamelCase_		):
        lowercase_       :Union[str, Any]     =       B'''\x80''' + (B'''\x00''' * (63 - (len(UpperCamelCase_		) + 8) % 64))
        lowercase_       :Any     =       struct.pack('''>Q'''   ,							(len(UpperCamelCase_		) * 8)		)
        return data + padding + big_endian_integer
   def 		UpperCamelCase  (     self		):
        # Convert into blocks of 64 bytes
        lowercase_       :Union[str, 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
             lowercase_       :Union[str, Any]     =       list(struct.unpack('''>16L'''   ,							UpperCamelCase_		)		)
             # add 48 0-ed integers
             words += [0] * 48

             lowercase_    ,      lowercase_    ,      lowercase_    ,      lowercase_    ,      lowercase_    ,      lowercase_    ,      lowercase_    ,      lowercase_       :str     =       self.hashes

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

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

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

                  lowercase_    ,      lowercase_    ,      lowercase_    ,      lowercase_    ,      lowercase_    ,      lowercase_    ,      lowercase_    ,      lowercase_       :str     =       (
                      g,
                      f,
                      e,
                      ((d + tempa) % 0X100000000),
                      c,
                      b,
                      a,
                      ((tempa + tempa) % 0X100000000),
                  )

             lowercase_       :List[Any]     =       [a, b, c, d, e, f, g, h]

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

        lowercase_       :Optional[int]     =       ''''''.join([hex(UpperCamelCase_		)[2:].zfill(8		) for value in self.hashes]		)




   def 		UpperCamelCase  (     self   ,							UpperCamelCase_   ,							UpperCamelCase_		):
        return 0XFFFFFFFF & (value << (32 - rotations)) | (value >> rotations)






class 							UpperCamelCase					(		unittest.TestCase     ):


   '''simple docstring'''







   def 		UpperCamelCase  (     self		):
        import hashlib

        lowercase_       :Optional[Any]     =       bytes('''Test String'''   ,							'''utf-8'''		)
        self.assertEqual(SHAaaa(UpperCamelCase_		).hash   ,							hashlib.shaaaa(UpperCamelCase_		).hexdigest()		)




def     UpperCamelCase    (      )					->							str:
     '''simple docstring'''





     import doctest

     doctest.testmod()

     lowercase_       :Optional[int]     =       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_       :Dict     =       parser.parse_args()

     lowercase_       :Union[str, Any]     =       args.input_string

     # hash input should be a bytestring
     if args.input_file:
          with open(args.input_file       ,		'''rb'''		) as f:
               lowercase_       :str     =       f.read()
     else:
          lowercase_       :Optional[int]     =       bytes(_snake_case       ,		'''utf-8'''		)

     print(SHAaaa(_snake_case		).hash		)


if __name__ == "__main__":
   main()





from torch import nn




def     UpperCamelCase    (      _a		)					->							str:
     '''simple docstring'''





     if act_fn in ["swish", "silu"]:
          return nn.SiLU()
     elif act_fn == "mish":
          return nn.Mish()
     elif act_fn == "gelu":
          return nn.GELU()
     else:
          raise ValueError(f"Unsupported activation function: {act_fn}"		)

