


import re
import string

import numpy as np

import datasets


__UpperCamelCase				:  List[str]      					=							'\nReturns the rate at which the input predicted strings exactly match their references, ignoring any strings input as part of the regexes_to_ignore list.\n'

__UpperCamelCase				:  Tuple      					=							'\nArgs:\n    predictions: List of predicted texts.\n    references: List of reference texts.\n    regexes_to_ignore: List, defaults to None. Regex expressions of characters to\n        ignore when calculating the exact matches. Note: these regexes are removed\n        from the input data before the changes based on the options below (e.g. ignore_case,\n        ignore_punctuation, ignore_numbers) are applied.\n    ignore_case: Boolean, defaults to False. If true, turns everything\n        to lowercase so that capitalization differences are ignored.\n    ignore_punctuation: Boolean, defaults to False. If true, removes all punctuation before\n        comparing predictions and references.\n    ignore_numbers: Boolean, defaults to False. If true, removes all punctuation before\n        comparing predictions and references.\nReturns:\n    exact_match: Dictionary containing exact_match rate. Possible values are between 0.0 and 100.0, inclusive.\nExamples:\n    >>> exact_match = datasets.load_metric("exact_match")\n    >>> refs = ["the cat", "theater", "YELLING", "agent007"]\n    >>> preds = ["cat?", "theater", "yelling", "agent"]\n    >>> results = exact_match.compute(references=refs, predictions=preds)\n    >>> print(round(results["exact_match"], 1))\n    25.0\n\n    >>> exact_match = datasets.load_metric("exact_match")\n    >>> refs = ["the cat", "theater", "YELLING", "agent007"]\n    >>> preds = ["cat?", "theater", "yelling", "agent"]\n    >>> results = exact_match.compute(references=refs, predictions=preds, regexes_to_ignore=["the ", "yell"], ignore_case=True, ignore_punctuation=True)\n    >>> print(round(results["exact_match"], 1))\n    50.0\n\n\n    >>> exact_match = datasets.load_metric("exact_match")\n    >>> refs = ["the cat", "theater", "YELLING", "agent007"]\n    >>> preds = ["cat?", "theater", "yelling", "agent"]\n    >>> results = exact_match.compute(references=refs, predictions=preds, regexes_to_ignore=["the ", "yell", "YELL"], ignore_case=True, ignore_punctuation=True)\n    >>> print(round(results["exact_match"], 1))\n    75.0\n\n    >>> exact_match = datasets.load_metric("exact_match")\n    >>> refs = ["the cat", "theater", "YELLING", "agent007"]\n    >>> preds = ["cat?", "theater", "yelling", "agent"]\n    >>> results = exact_match.compute(references=refs, predictions=preds, regexes_to_ignore=["the ", "yell", "YELL"], ignore_case=True, ignore_punctuation=True, ignore_numbers=True)\n    >>> print(round(results["exact_match"], 1))\n    100.0\n\n    >>> exact_match = datasets.load_metric("exact_match")\n    >>> refs = ["The cat sat on the mat.", "Theaters are great.", "It\'s like comparing oranges and apples."]\n    >>> preds = ["The cat sat on the mat?", "Theaters are great.", "It\'s like comparing apples and oranges."]\n    >>> results = exact_match.compute(references=refs, predictions=preds)\n    >>> print(round(results["exact_match"], 1))\n    33.3\n\n'

__UpperCamelCase				:  str      					=							'\n'





@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION    ,    _KWARGS_DESCRIPTION						)
class  lowerCAmelCase__(    datasets.Metric						):






    '''simple docstring'''





    def 					_lowerCamelCase (	self				:   Optional[int]	):





       '''simple docstring'''
       return datasets.MetricInfo(
           description=_DESCRIPTION       ,   citation=_CITATION       ,   inputs_description=_KWARGS_DESCRIPTION       ,   features=datasets.Features(
               {
                   '''predictions''': datasets.Value('''string'''       ,   id='''sequence'''	),
                   '''references''': datasets.Value('''string'''       ,   id='''sequence'''	),
               }	)       ,   reference_urls=[]       ,   )





    def 					_lowerCamelCase (	self				:   List[Any]       ,   __snake_case				:   List[str]       ,   __snake_case				:   Tuple       ,   __snake_case				:   Dict=None       ,   __snake_case				:   Optional[Any]=False       ,   __snake_case				:   Any=False       ,   __snake_case				:   List[str]=False       ,   ):





       '''simple docstring'''







       if regexes_to_ignore is not None:
          for s in regexes_to_ignore:
             UpperCAmelCase_							:      Tuple						=   np.array([re.sub(lowercase_       ,   ''''''       ,   lowercase_	) for x in predictions]	)
             UpperCAmelCase_							:      int						=   np.array([re.sub(lowercase_       ,   ''''''       ,   lowercase_	) for x in references]	)
       else:
          UpperCAmelCase_							:      Optional[int]						=   np.asarray(lowercase_	)
          UpperCAmelCase_							:      int						=   np.asarray(lowercase_	)

       if ignore_case:
          UpperCAmelCase_							:      Any						=   np.char.lower(lowercase_	)
          UpperCAmelCase_							:      Optional[Any]						=   np.char.lower(lowercase_	)

       if ignore_punctuation:
          UpperCAmelCase_							:      Optional[Any]						=   string.punctuation.maketrans(''''''       ,   ''''''       ,   string.punctuation	)
          UpperCAmelCase_							:      str						=   np.char.translate(lowercase_       ,   table=lowercase_	)
          UpperCAmelCase_							:      Optional[Any]						=   np.char.translate(lowercase_       ,   table=lowercase_	)

       if ignore_numbers:
          UpperCAmelCase_							:      List[str]						=   string.digits.maketrans(''''''       ,   ''''''       ,   string.digits	)
          UpperCAmelCase_							:      Any						=   np.char.translate(lowercase_       ,   table=lowercase_	)
          UpperCAmelCase_							:      List[Any]						=   np.char.translate(lowercase_       ,   table=lowercase_	)

       UpperCAmelCase_							:      Any						=   predictions == references

       return {"exact_match": np.mean(lowercase_	) * 100}



import argparse
import hashlib  # hashlib is only used inside the Test class
import struct





class  lowerCAmelCase__:






    '''simple docstring'''





    def __init__(	self				:   List[str]       ,   __snake_case				:   Union[str, Any]	):





       '''simple docstring'''
       UpperCAmelCase_							:      str						=   data
       UpperCAmelCase_							:      List[Any]						=   [0X67_45_23_01, 0Xef_cd_ab_89, 0X98_ba_dc_fe, 0X10_32_54_76, 0Xc3_d2_e1_f0]





    @staticmethod
    def 					_lowerCamelCase (	__snake_case				:   Dict       ,   __snake_case				:   Dict	):





       '''simple docstring'''
       return ((n << b) | (n >> (32 - b))) & 0Xff_ff_ff_ff





    def 					_lowerCamelCase (	self				:   Dict	):





       '''simple docstring'''
       UpperCAmelCase_							:      Optional[int]						=   B'''\x80''' + B'''\x00''' * (63 - (len(self.data	) + 8) % 64)
       UpperCAmelCase_							:      Union[str, Any]						=   self.data + padding + struct.pack('''>Q'''       ,   8 * len(self.data	)	)
       return padded_data





    def 					_lowerCamelCase (	self				:   Tuple	):





       '''simple docstring'''
       return [
           self.padded_data[i : i + 64] for i in range(0       ,   len(self.padded_data	)       ,   64	)
       ]





    def 					_lowerCamelCase (	self				:   Dict       ,   __snake_case				:   Optional[int]	):





       '''simple docstring'''
       UpperCAmelCase_							:      Any						=   list(struct.unpack('''>16L'''       ,   __snake_case	)	) + [0] * 64
       for i in range(16       ,   80	):
          UpperCAmelCase_							:      str						=   self.rotate((w[i - 3] ^ w[i - 8] ^ w[i - 14] ^ w[i - 16])       ,   1	)
       return w





    def 					_lowerCamelCase (	self				:   Union[str, Any]	):





       '''simple docstring'''
       UpperCAmelCase_							:      Optional[int]						=   self.padding()
       UpperCAmelCase_							:      str						=   self.split_blocks()
       for block in self.blocks:
          UpperCAmelCase_							:      Any						=   self.expand_block(__snake_case	)
          UpperCAmelCase_		,      UpperCAmelCase_		,      UpperCAmelCase_		,      UpperCAmelCase_		,      UpperCAmelCase_							:      List[str]						=   self.h
          for i in range(0       ,   80	):
             if 0 <= i < 20:
                UpperCAmelCase_							:      Optional[Any]						=   (b & c) | ((~b) & d)
                UpperCAmelCase_							:      Optional[Any]						=   0X5a_82_79_99
             elif 20 <= i < 40:
                UpperCAmelCase_							:      List[Any]						=   b ^ c ^ d
                UpperCAmelCase_							:      str						=   0X6e_d9_eb_a1
             elif 40 <= i < 60:
                UpperCAmelCase_							:      str						=   (b & c) | (b & d) | (c & d)
                UpperCAmelCase_							:      Optional[int]						=   0X8f_1b_bc_dc
             elif 60 <= i < 80:
                UpperCAmelCase_							:      Union[str, Any]						=   b ^ c ^ d
                UpperCAmelCase_							:      Dict						=   0Xca_62_c1_d6
             UpperCAmelCase_		,      UpperCAmelCase_		,      UpperCAmelCase_		,      UpperCAmelCase_		,      UpperCAmelCase_							:      int						=   (
                 self.rotate(__snake_case       ,   5	) + f + e + k + expanded_block[i] & 0Xff_ff_ff_ff,
                 a,
                 self.rotate(__snake_case       ,   30	),
                 c,
                 d,
             )
          UpperCAmelCase_							:      Optional[Any]						=   (
              self.h[0] + a & 0Xff_ff_ff_ff,
              self.h[1] + b & 0Xff_ff_ff_ff,
              self.h[2] + c & 0Xff_ff_ff_ff,
              self.h[3] + d & 0Xff_ff_ff_ff,
              self.h[4] + e & 0Xff_ff_ff_ff,
          )
       return ("{:08x}" * 5).format(*self.h	)





def      snake_case_						( ):
   UpperCAmelCase_							:      Tuple						=   B'''Test String'''
   assert SHAaHash(__lowercase       ).final_hash() == hashlib.shaa(__lowercase       ).hexdigest()  # noqa: S324
def      snake_case_						( ):
   UpperCAmelCase_							:      int						=   argparse.ArgumentParser(description='''Process some strings or files'''       )
   parser.add_argument(
       '''--string'''			,       dest='''input_string'''			,       default='''Hello World!! Welcome to Cryptography'''			,       help='''Hash the string'''			,       )
   parser.add_argument('''--file'''			,       dest='''input_file'''			,       help='''Hash contents of a file'''       )
   UpperCAmelCase_							:      List[Any]						=   parser.parse_args()
   UpperCAmelCase_							:      Optional[Any]						=   args.input_string
   # In any case hash input should be a bytestring
   if args.input_file:
      with open(args.input_file			,       '''rb'''       ) as f:
         UpperCAmelCase_							:      List[str]						=   f.read()
   else:
      UpperCAmelCase_							:      Tuple						=   bytes(__lowercase			,       '''utf-8'''       )
   print(SHAaHash(__lowercase       ).final_hash()       )


if __name__ == "__main__":
       main()
       import doctest

       doctest.testmod()