



"""simple docstring"""





import argparse
import struct
import unittest
class    lowercase__     :







       '''simple docstring'''


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


             '''simple docstring'''




             UpperCAmelCase_    				=							data

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

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



       @staticmethod
       def   lowercase__       (							_UpperCAmelCase    :						bytes					)				->		bytes:


             '''simple docstring'''




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



       def   lowercase__       (							self    :						Tuple					)				->		None:


             '''simple docstring'''




             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_				,					UpperCAmelCase_				,					UpperCAmelCase_				,					UpperCAmelCase_				,					UpperCAmelCase_				,					UpperCAmelCase_				,					UpperCAmelCase_				,					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
                               ) % 0x1_00_00_00_00

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

                         UpperCAmelCase_				,					UpperCAmelCase_				,					UpperCAmelCase_				,					UpperCAmelCase_				,					UpperCAmelCase_				,					UpperCAmelCase_				,					UpperCAmelCase_				,					UpperCAmelCase_    				=							(
                             g,
                             f,
                             e,
                             ((d + tempa) % 0x1_00_00_00_00),
                             c,
                             b,
                             a,
                             ((tempa + tempa) % 0x1_00_00_00_00),
                         )

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

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

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







       def   lowercase__       (							self    :						int	,       _UpperCAmelCase    :						int	,       _UpperCAmelCase    :						int					)				->		int:


             '''simple docstring'''




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



class    lowercase__     (					unittest.TestCase   ):







       '''simple docstring'''


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


             '''simple docstring'''




             import hashlib

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



def      a__			(   ):
      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(lowerCAmelCase__			,    "utf-8"   )

      print(SHAaaa(lowerCAmelCase__   ).hash   )


if __name__ == "__main__":
  main()









"""simple docstring"""





from typing import Dict, List, Optional, Union

import numpy as np

from ...image_processing_utils import BaseImageProcessor, BatchFeature, get_size_dict
from ...image_transforms import (
    center_crop,
    get_resize_output_image_size,
    normalize,
    rescale,
    resize,
    to_channel_dimension_format,
)
from ...image_utils import (
    IMAGENET_STANDARD_MEAN,
    IMAGENET_STANDARD_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, is_vision_available, logging


if is_vision_available():
  import PIL


lowerCamelCase      =		logging.get_logger(__name__)
class    lowercase__     (					SCREAMING_SNAKE_CASE   ):







       '''simple docstring'''


       UpperCamelCase		=  ['''pixel_values''']



       def __init__(							self    :						str	,       _UpperCAmelCase    :						bool = True	,       _UpperCAmelCase    :						Dict[str, int] = None	,       _UpperCAmelCase    :						float = None	,       _UpperCAmelCase    :						PILImageResampling = PILImageResampling.BILINEAR	,       _UpperCAmelCase    :						bool = True	,       _UpperCAmelCase    :						Union[int, float] = 1 / 255	,       _UpperCAmelCase    :						bool = True	,       _UpperCAmelCase    :						Optional[Union[float, List[float]]] = None	,       _UpperCAmelCase    :						Optional[Union[float, List[float]]] = None	,       **_UpperCAmelCase    :						Optional[int]	,       )				->		None:


             '''simple docstring'''




             super().__init__(**_UpperCAmelCase					)
             UpperCAmelCase_    				=							size if size is not None else {"shortest_edge": 384}
             UpperCAmelCase_    				=							get_size_dict(_UpperCAmelCase	,       default_to_square=_UpperCAmelCase					)

             UpperCAmelCase_    				=							do_resize
             UpperCAmelCase_    				=							size
             # Default value set here for backwards compatibility where the value in config is None
             UpperCAmelCase_    				=							crop_pct if crop_pct is not None else 224 / 256
             UpperCAmelCase_    				=							resample
             UpperCAmelCase_    				=							do_rescale
             UpperCAmelCase_    				=							rescale_factor
             UpperCAmelCase_    				=							do_normalize
             UpperCAmelCase_    				=							image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
             UpperCAmelCase_    				=							image_std if image_std is not None else IMAGENET_STANDARD_STD



       def   lowercase__       (							self    :						Union[str, Any]	,       _UpperCAmelCase    :						np.ndarray	,       _UpperCAmelCase    :						Dict[str, int]	,       _UpperCAmelCase    :						float	,       _UpperCAmelCase    :						PILImageResampling = PILImageResampling.BICUBIC	,       _UpperCAmelCase    :						Optional[Union[str, ChannelDimension]] = None	,       **_UpperCAmelCase    :						Optional[int]	,       )				->		np.ndarray:


             '''simple docstring'''




             UpperCAmelCase_    				=							get_size_dict(_UpperCAmelCase	,       default_to_square=_UpperCAmelCase					)
             if "shortest_edge" not in size:
                   raise ValueError(F"""Size dictionary must contain 'shortest_edge' key. Got {size.keys()}"""					)
             UpperCAmelCase_    				=							size["shortest_edge"]

             if shortest_edge < 384:
                   # maintain same ratio, resizing shortest edge to shortest_edge/crop_pct
                   UpperCAmelCase_    				=							int(shortest_edge / crop_pct					)
                   UpperCAmelCase_    				=							get_resize_output_image_size(_UpperCAmelCase	,       size=_UpperCAmelCase	,       default_to_square=_UpperCAmelCase					)
                   UpperCAmelCase_    				=							resize(image=_UpperCAmelCase	,       size=_UpperCAmelCase	,       resample=_UpperCAmelCase	,       data_format=_UpperCAmelCase	,       **_UpperCAmelCase					)
                   # then crop to (shortest_edge, shortest_edge)
                   return center_crop(image=_UpperCAmelCase	,       size=(shortest_edge, shortest_edge)	,       data_format=_UpperCAmelCase	,       **_UpperCAmelCase					)
             else:
                   # warping (no cropping) when evaluated at 384 or larger
                   return resize(
                       _UpperCAmelCase	,       size=(shortest_edge, shortest_edge)	,       resample=_UpperCAmelCase	,       data_format=_UpperCAmelCase	,       **_UpperCAmelCase					)



       def   lowercase__       (							self    :						Tuple	,       _UpperCAmelCase    :						np.ndarray	,       _UpperCAmelCase    :						Union[int, float]	,       _UpperCAmelCase    :						Optional[Union[str, ChannelDimension]] = None	,       **_UpperCAmelCase    :						List[Any]	,       )				->		Any:


             '''simple docstring'''




             return rescale(_UpperCAmelCase	,       scale=_UpperCAmelCase	,       data_format=_UpperCAmelCase	,       **_UpperCAmelCase					)



       def   lowercase__       (							self    :						Dict	,       _UpperCAmelCase    :						np.ndarray	,       _UpperCAmelCase    :						Union[float, List[float]]	,       _UpperCAmelCase    :						Union[float, List[float]]	,       _UpperCAmelCase    :						Optional[Union[str, ChannelDimension]] = None	,       **_UpperCAmelCase    :						List[str]	,       )				->		np.ndarray:


             '''simple docstring'''




             return normalize(_UpperCAmelCase	,       mean=_UpperCAmelCase	,       std=_UpperCAmelCase	,       data_format=_UpperCAmelCase	,       **_UpperCAmelCase					)







       def   lowercase__       (							self    :						Union[str, Any]	,       _UpperCAmelCase    :						ImageInput	,       _UpperCAmelCase    :						bool = None	,       _UpperCAmelCase    :						Dict[str, int] = None	,       _UpperCAmelCase    :						float = None	,       _UpperCAmelCase    :						PILImageResampling = None	,       _UpperCAmelCase    :						bool = None	,       _UpperCAmelCase    :						float = None	,       _UpperCAmelCase    :						bool = None	,       _UpperCAmelCase    :						Optional[Union[float, List[float]]] = None	,       _UpperCAmelCase    :						Optional[Union[float, List[float]]] = None	,       _UpperCAmelCase    :						Optional[Union[str, TensorType]] = None	,       _UpperCAmelCase    :						ChannelDimension = ChannelDimension.FIRST	,       **_UpperCAmelCase    :						Optional[int]	,       )				->		PIL.Image.Image:


             '''simple docstring'''




             UpperCAmelCase_    				=							do_resize if do_resize is not None else self.do_resize
             UpperCAmelCase_    				=							crop_pct if crop_pct is not None else self.crop_pct
             UpperCAmelCase_    				=							resample if resample is not None else self.resample
             UpperCAmelCase_    				=							do_rescale if do_rescale is not None else self.do_rescale
             UpperCAmelCase_    				=							rescale_factor if rescale_factor is not None else self.rescale_factor
             UpperCAmelCase_    				=							do_normalize if do_normalize is not None else self.do_normalize
             UpperCAmelCase_    				=							image_mean if image_mean is not None else self.image_mean
             UpperCAmelCase_    				=							image_std if image_std is not None else self.image_std

             UpperCAmelCase_    				=							size if size is not None else self.size
             UpperCAmelCase_    				=							get_size_dict(_UpperCAmelCase	,       default_to_square=_UpperCAmelCase					)

             UpperCAmelCase_    				=							make_list_of_images(_UpperCAmelCase					)

             if not valid_images(_UpperCAmelCase					):
                   raise ValueError(
                       "Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, "
                       "torch.Tensor, tf.Tensor or jax.ndarray."					)

             if do_resize and size is None or resample is None:
                   raise ValueError("Size and resample must be specified if do_resize is True."					)

             if do_resize and size["shortest_edge"] < 384 and crop_pct is None:
                   raise ValueError("crop_pct must be specified if size < 384."					)

             if do_rescale and rescale_factor is None:
                   raise ValueError("Rescale factor must be specified if do_rescale is True."					)

             if do_normalize and (image_mean is None or image_std is None):
                   raise ValueError("Image mean and std must be specified if do_normalize is True."					)

             # All transformations expect numpy arrays.
             UpperCAmelCase_    				=							[to_numpy_array(_UpperCAmelCase					) for image in images]

             if do_resize:
                   UpperCAmelCase_    				=							[self.resize(image=_UpperCAmelCase	,       size=_UpperCAmelCase	,       crop_pct=_UpperCAmelCase	,       resample=_UpperCAmelCase					) for image in images]

             if do_rescale:
                   UpperCAmelCase_    				=							[self.rescale(image=_UpperCAmelCase	,       scale=_UpperCAmelCase					) for image in images]

             if do_normalize:
                   UpperCAmelCase_    				=							[self.normalize(image=_UpperCAmelCase	,       mean=_UpperCAmelCase	,       std=_UpperCAmelCase					) for image in images]

             UpperCAmelCase_    				=							[to_channel_dimension_format(_UpperCAmelCase	,       _UpperCAmelCase					) for image in images]

             UpperCAmelCase_    				=							{"pixel_values": images}
             return BatchFeature(data=_UpperCAmelCase	,       tensor_type=_UpperCAmelCase					)




