
import argparse
import struct
import unittest




class 						__lowercase		:




      """simple docstring"""





      def __init__(				self    ,				A     )		->    str:
         snake_case				:    Dict           =	data

         # Initialize hash values
         snake_case				:    Dict           =	[
             0X6a09_e667,
             0Xbb67_ae85,
             0X3c6e_f372,
             0Xa54f_f53a,
             0X510e_527f,
             0X9b05_688c,
             0X1f83_d9ab,
             0X5be0_cd19,
         ]

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

         snake_case				:    Union[str, Any]           =	self.preprocessing(self.data     )
         self.final_hash()

      @staticmethod
      def      UpperCAmelCase				(				A     )		->    Tuple:
         snake_case				:    Dict           =	B"""\x80""" + (B"""\x00""" * (6_3 - (len(__lowerCAmelCase     ) + 8) % 6_4))
         snake_case				:    Dict           =	struct.pack(""">Q"""    ,				(len(__lowerCAmelCase     ) * 8)     )
         return data + padding + big_endian_integer

      def      UpperCAmelCase				(				self     )		->    Dict:
         snake_case				:    List[Any]           =	[
             self.preprocessed_data[x : x + 6_4]
             for x in range(0    ,				len(self.preprocessed_data     )    ,				6_4     )
         ]

         for block in self.blocks:
            # Convert the given block into a list of 4 byte integers
            snake_case				:    Optional[Any]           =	list(struct.unpack(""">16L"""    ,				__lowerCAmelCase     )     )
            # add 48 0-ed integers
            words += [0] * 4_8

            snake_case     , snake_case     , snake_case     , snake_case     , snake_case     , snake_case     , snake_case     , snake_case				:    Union[str, Any]           =	self.hashes

            for index in range(0    ,				6_4     ):
               if index > 1_5:
                  # modify the zero-ed indexes at the end of the array
                  snake_case				:    List[str]           =	(
                      self.ror(words[index - 1_5]    ,				7     )
                      ^ self.ror(words[index - 1_5]    ,				1_8     )
                      ^ (words[index - 1_5] >> 3)
                  )
                  snake_case				:    List[Any]           =	(
                      self.ror(words[index - 2]    ,				1_7     )
                      ^ self.ror(words[index - 2]    ,				1_9     )
                      ^ (words[index - 2] >> 1_0)
                  )

                  snake_case				:    Dict           =	(
                      words[index - 1_6] + sa + words[index - 7] + sa
                  ) % 0X1_0000_0000

               # Compression
               snake_case				:    Optional[Any]           =	self.ror(__lowerCAmelCase    ,				6     ) ^ self.ror(__lowerCAmelCase    ,				1_1     ) ^ self.ror(__lowerCAmelCase    ,				2_5     )
               snake_case				:    int           =	(e & f) ^ ((~e & 0Xffff_ffff) & g)
               snake_case				:    int           =	(
                   h + sa + ch + self.round_constants[index] + words[index]
               ) % 0X1_0000_0000
               snake_case				:    Union[str, Any]           =	self.ror(__lowerCAmelCase    ,				2     ) ^ self.ror(__lowerCAmelCase    ,				1_3     ) ^ self.ror(__lowerCAmelCase    ,				2_2     )
               snake_case				:    Dict           =	(a & b) ^ (a & c) ^ (b & c)
               snake_case				:    Optional[int]           =	(sa + maj) % 0X1_0000_0000

               snake_case     , snake_case     , snake_case     , snake_case     , snake_case     , snake_case     , snake_case     , snake_case				:    Optional[Any]           =	(
                   g,
                   f,
                   e,
                   ((d + tempa) % 0X1_0000_0000),
                   c,
                   b,
                   a,
                   ((tempa + tempa) % 0X1_0000_0000),
               )

            snake_case				:    Optional[int]           =	[a, b, c, d, e, f, g, h]

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

         snake_case				:    str           =	"""""".join([hex(__lowerCAmelCase     )[2:].zfill(8     ) for value in self.hashes]     )

      def      UpperCAmelCase				(				self    ,				A    ,				A     )		->    int:
         return 0Xffff_ffff & (value << (3_2 - rotations)) | (value >> rotations)




class 						__lowercase		(unittest.TestCase							):




      """simple docstring"""





      def      UpperCAmelCase				(				self     )		->    Tuple:
         import hashlib

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




def 						SCREAMING_SNAKE_CASE__ (   )  ->       None:
   import doctest

   doctest.testmod()

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

   snake_case				:    Union[str, Any]           =	parser.parse_args()

   snake_case				:    Optional[int]           =	args.input_string

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

   print(SHAaaa(lowerCAmelCase__					).hash					)


if __name__ == "__main__":
       main()











from io import BytesIO
from typing import List, Union

import requests

from ..utils import add_end_docstrings, is_decord_available, is_torch_available, logging, requires_backends
from .base import PIPELINE_INIT_ARGS, Pipeline


if is_decord_available():
       import numpy as np
       from decord import VideoReader


if is_torch_available():
       from ..models.auto.modeling_auto import MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING

lowerCamelCase	:	int				=   logging.get_logger(__name__)




@add_end_docstrings(UpperCamelCase__							)
class 						__lowercase		(UpperCamelCase__							):




      """simple docstring"""





      def __init__(				self    ,				*A    ,				**A     )		->    Optional[int]:
         super().__init__(*A    ,				**A     )
         requires_backends(self    ,				"""decord"""     )
         self.check_model_type(A     )

      def      UpperCAmelCase				(				self    ,				A=None    ,				A=None    ,				A=None     )		->    int:
         snake_case				:    Any           =	{}
         if frame_sampling_rate is not None:
            snake_case				:    int           =	frame_sampling_rate
         if num_frames is not None:
            snake_case				:    Union[str, Any]           =	num_frames

         snake_case				:    str           =	{}
         if top_k is not None:
            snake_case				:    Optional[int]           =	top_k
         return preprocess_params, {}, postprocess_params

      def __call__(				self    ,				A    ,				**A     )		->    Dict:
         return super().__call__(A    ,				**A     )

      def      UpperCAmelCase				(				self    ,				A    ,				A=None    ,				A=1     )		->    Tuple:
         if num_frames is None:
            snake_case				:    Tuple           =	self.model.config.num_frames

         if video.startswith("""http://"""     ) or video.startswith("""https://"""     ):
            snake_case				:    Optional[int]           =	BytesIO(requests.get(A     ).content     )

         snake_case				:    Optional[Any]           =	VideoReader(A     )
         videoreader.seek(0     )

         snake_case				:    Optional[Any]           =	0
         snake_case				:    Optional[Any]           =	num_frames * frame_sampling_rate - 1
         snake_case				:    Any           =	np.linspace(A    ,				A    ,				num=A    ,				dtype=np.intaa     )

         snake_case				:    int           =	videoreader.get_batch(A     ).asnumpy()
         snake_case				:    List[Any]           =	list(A     )

         snake_case				:    Optional[Any]           =	self.image_processor(A    ,				return_tensors=self.framework     )
         return model_inputs

      def      UpperCAmelCase				(				self    ,				A     )		->    List[str]:
         snake_case				:    Dict           =	self.model(**A     )
         return model_outputs

      def      UpperCAmelCase				(				self    ,				A    ,				A=5     )		->    int:
         if top_k > self.model.config.num_labels:
            snake_case				:    str           =	self.model.config.num_labels

         if self.framework == "pt":
            snake_case				:    List[Any]           =	model_outputs.logits.softmax(-1     )[0]
            snake_case     , snake_case				:    Tuple           =	probs.topk(A     )
         else:
            raise ValueError(f"""Unsupported framework: {self.framework}"""     )

         snake_case				:    List[Any]           =	scores.tolist()
         snake_case				:    str           =	ids.tolist()
         return [{"score": score, "label": self.model.config.idalabel[_id]} for score, _id in zip(A    ,				A     )]





