




import argparse
import struct
import unittest



class 			_UpperCamelCase      :
      def __init__(			self   :List[str] ,      lowerCamelCase   :bytes      )     ->			Dict:
       UpperCAmelCase__							 =						data

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

       # Initialize round constants
       UpperCAmelCase__							 =						[
           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,
       ]

       UpperCAmelCase__							 =						self.preprocessing(self.data      )
       self.final_hash()
      @staticmethod
      def 	UpperCAmelCase_						(			lowerCamelCase   :bytes      )     ->			Dict:
       UpperCAmelCase__							 =						B'''\x80''' + (B'''\x00''' * (63 - (len(UpperCamelCase__      ) + 8) % 64))
       UpperCAmelCase__							 =						struct.pack(">Q" ,      (len(UpperCamelCase__      ) * 8)      )
       return data + padding + big_endian_integer
      def 	UpperCAmelCase_						(			self   :Union[str, Any]      )     ->			Tuple:
       UpperCAmelCase__							 =						[
           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
        UpperCAmelCase__							 =						list(struct.unpack(">16L" ,      UpperCamelCase__      )      )
        # add 48 0-ed integers
        words += [0] * 48

        UpperCAmelCase__							 =						self.hashes

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

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

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

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

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

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

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







      def 	UpperCAmelCase_						(			self   :Union[str, Any] ,      lowerCamelCase   :int ,      lowerCamelCase   :int      )     ->			Union[str, Any]:
       return 0xffffffff & (value << (32 - rotations)) | (value >> rotations)



class 			_UpperCamelCase      (				unittest.TestCase		):
      def 	UpperCAmelCase_						(			self   :Optional[Any]      )     ->			int:
       import hashlib

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



def 						lowerCAmelCase		(		):




 """simple docstring"""







 import doctest

 doctest.testmod()

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

 UpperCAmelCase__							 =						parser.parse_args()

 UpperCAmelCase__							 =						args.input_string

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

 print(SHAaaa(_lowercase	).hash	)


if __name__ == "__main__":
  main()











import torch

from transformers import AutoModel
class 			_UpperCamelCase      (				torch.nn.Module		):
      def __init__(			self   :str ,      lowerCamelCase   :Tuple="sayef/fsner-bert-base-uncased"      )     ->			int:
       super(lowerCamelCase ,      self      ).__init__()

       UpperCAmelCase__							 =						AutoModel.from_pretrained(lowerCamelCase ,      return_dict=lowerCamelCase      )
       UpperCAmelCase__							 =						torch.nn.CosineSimilarity(3 ,      1e-08      )
       UpperCAmelCase__							 =						torch.nn.Softmax(dim=1      )
      def 	UpperCAmelCase_						(			self   :Union[str, Any] ,      **lowerCamelCase   :Tuple      )     ->			Dict:
       return self.bert(**lowerCamelCase      ).last_hidden_state
      def 	UpperCAmelCase_						(			self   :Any ,      lowerCamelCase   :Union[str, Any]      )     ->			Union[str, Any]:
       return token_embeddings.sum(2 ,      keepdim=lowerCamelCase      )
      def 	UpperCAmelCase_						(			self   :Dict ,      lowerCamelCase   :List[Any] ,      lowerCamelCase   :int ,      lowerCamelCase   :Union[str, Any]=1      )     ->			Dict:
       return self.softmax(T * self.cos(lowerCamelCase ,      lowerCamelCase      )      )







      def 	UpperCAmelCase_						(			self   :Union[str, Any] ,      lowerCamelCase   :Any ,      lowerCamelCase   :Any      )     ->			Union[str, Any]:
       UpperCAmelCase__							 =						W_supports["sizes"].tolist()
       UpperCAmelCase__							 =						W_supports["start_token_id"].item()
       UpperCAmelCase__							 =						W_supports["end_token_id"].item()

       del W_supports["sizes"]
       del W_supports["start_token_id"]
       del W_supports["end_token_id"]

       UpperCAmelCase__							 =						self.BERT(**lowerCamelCase      )
       UpperCAmelCase__							 =						self.BERT(**lowerCamelCase      )

       UpperCAmelCase__							 =						None
       UpperCAmelCase__							 =						None

       UpperCAmelCase__							 =						W_supports["input_ids"] == start_token_id
       UpperCAmelCase__							 =						W_supports["input_ids"] == end_token_id

       for i, size in enumerate(lowerCamelCase      ):
        if i == 0:
         UpperCAmelCase__							 =						0
        else:
         UpperCAmelCase__							 =						support_sizes[i - 1]

        UpperCAmelCase__							 =						S[s : s + size][start_token_masks[s : s + size]]
        UpperCAmelCase__							 =						S[s : s + size][end_token_masks[s : s + size]]

        UpperCAmelCase__							 =						torch.matmul(q[i] ,      s_start.T      ).sum(1      ).softmax(0      )
        UpperCAmelCase__							 =						torch.matmul(q[i] ,      s_end.T      ).sum(1      ).softmax(0      )

        if p_starts is not None:
         UpperCAmelCase__							 =						torch.vstack((p_starts, p_start)      )
         UpperCAmelCase__							 =						torch.vstack((p_ends, p_end)      )
        else:
         UpperCAmelCase__							 =						p_start
         UpperCAmelCase__							 =						p_end

       return p_starts, p_ends





