





import argparse
import struct
import unittest
class        SCREAMING_SNAKE_CASE     :


   def __init__(					self    :       Tuple    ,  a    :       bytes )->     None:





     """simple docstring"""







     lowercase__			    =						data

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

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


   @staticmethod
   def  SCREAMING_SNAKE_CASE_							(					a    :       bytes )->     bytes:





     """simple docstring"""







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


   def  SCREAMING_SNAKE_CASE_							(					self    :       Tuple )->     None:





     """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'    ,  _UpperCAmelCase ) )
       # 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
           ) % 0x100_000_000

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

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

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

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

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


   def  SCREAMING_SNAKE_CASE_							(					self    :       int    ,  a    :       int    ,  a    :       int )->     int:





     """simple docstring"""







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






class        SCREAMING_SNAKE_CASE     (unittest.TestCase   ):


   def  SCREAMING_SNAKE_CASE_							(					self    :       Optional[Any] )->     None:





     """simple docstring"""







     import hashlib

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






def     __UpperCamelCase						()       ->     Any:
  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(lowerCAmelCase__	,		'utf-8'	)

  print(SHAaaa(lowerCAmelCase__	).hash	)


if __name__ == "__main__":
      main()








class        SCREAMING_SNAKE_CASE     :  # Public class to implement a graph


   def __init__(					self    :       int    ,  a    :       int    ,  a    :       int    ,  a    :       list[list[bool]] )->     None:





     """simple docstring"""







     lowercase__			    =						row
     lowercase__			    =						col
     lowercase__			    =						graph


   def  SCREAMING_SNAKE_CASE_							(					self    :       Dict    ,  a    :       int    ,  a    :       int    ,  a    :       list[list[bool]] )->     bool:





     """simple docstring"""







     return (
         0 <= i < self.ROW
         and 0 <= j < self.COL
         and not visited[i][j]
         and self.graph[i][j]
     )


   def  SCREAMING_SNAKE_CASE_							(					self    :       List[str]    ,  a    :       int    ,  a    :       int    ,  a    :       list[list[bool]] )->     None:





     """simple docstring"""







     lowercase__			    =						[-1, -1, -1, 0, 0, 1, 1, 1]  # Coordinate order
     lowercase__			    =						[-1, 0, 1, -1, 1, -1, 0, 1]
     lowercase__			    =						True  # Make those cells visited
     for k in range(8 ):
       if self.is_safe(i + row_nbr[k]    ,  j + col_nbr[k]    ,  a ):
         self.diffs(i + row_nbr[k]    ,  j + col_nbr[k]    ,  a )


   def  SCREAMING_SNAKE_CASE_							(					self    :       List[str] )->     int:  # And finally, count all islands.





     """simple docstring"""







     lowercase__			    =						[[False for j in range(self.COL )] for i in range(self.ROW )]
     lowercase__			    =						0
     for i in range(self.ROW ):
       for j in range(self.COL ):
         if visited[i][j] is False and self.graph[i][j] == 1:
           self.diffs(a    ,  a    ,  a )
           count += 1
     return count


