



"""simple docstring"""







from collections.abc import Generator
from math import sin

def 				UpperCamelCase_    (    lowerCAmelCase__      :				bytes						)						->   Tuple:

  """simple docstring"""




  if len(__a						) != 32:
    raise ValueError('Input must be of length 32'						)

  lowerCAmelCase_   :				List[Any]								= b''
  for i in [3, 2, 1, 0]:
    little_endian += string_aa[8 * i : 8 * i + 8]
  return little_endian

def 				UpperCamelCase_    (    lowerCAmelCase__      :				int						)						->   Optional[Any]:

  """simple docstring"""




  if i < 0:
    raise ValueError('Input must be non-negative'						)

  lowerCAmelCase_   :				List[str]								= format(__a    ,   '08x'						)[-8:]
  lowerCAmelCase_   :				Dict								= b''
  for i in [3, 2, 1, 0]:
    little_endian_hex += hex_rep[2 * i : 2 * i + 2].encode('utf-8'						)
  return little_endian_hex

def 				UpperCamelCase_    (    lowerCAmelCase__      :				bytes						)						->   str:

  """simple docstring"""




  lowerCAmelCase_   :				List[Any]								= b''
  for char in message:
    bit_string += format(__a    ,   '08b'						).encode('utf-8'						)
  lowerCAmelCase_   :				List[str]								= format(len(__a						)    ,   '064b'						).encode('utf-8'						)

  # Pad bit_string to a multiple of 512 chars
  bit_string += b"1"
  while len(__a						) % 512 != 448:
    bit_string += b"0"
  bit_string += to_little_endian(start_len[32:]						) + to_little_endian(start_len[:32]						)

  return bit_string

def 				UpperCamelCase_    (    lowerCAmelCase__      :				bytes						)						->   Tuple:

  """simple docstring"""




  if len(__a						) % 512 != 0:
    raise ValueError('Input must have length that\'s a multiple of 512'						)

  for pos in range(0    ,   len(__a						)    ,   512						):
    lowerCAmelCase_   :				Optional[Any]								= bit_string[pos : pos + 512]
    lowerCAmelCase_   :				Optional[Any]								= []
    for i in range(0    ,   512    ,   32						):
      block_words.append(int(to_little_endian(block[i : i + 32]						)    ,   2						)						)
    yield block_words

def 				UpperCamelCase_    (    lowerCAmelCase__      :				int						)						->   Tuple:

  """simple docstring"""




  if i < 0:
    raise ValueError('Input must be non-negative'						)

  lowerCAmelCase_   :				Union[str, Any]								= format(__a    ,   '032b'						)
  lowerCAmelCase_   :				Dict								= ''
  for c in i_str:
    new_str += "1" if c == "0" else "0"
  return int(__a    ,   2						)

def 				UpperCamelCase_    (    lowerCAmelCase__      :				int    ,   lowerCAmelCase__      :				int						)						->   str:

  """simple docstring"""




  return (a + b) % 2**32

def 				UpperCamelCase_    (    lowerCAmelCase__      :				int    ,   lowerCAmelCase__      :				int						)						->   List[Any]:

  """simple docstring"""




  if i < 0:
    raise ValueError('Input must be non-negative'						)
  if shift < 0:
    raise ValueError('Shift must be non-negative'						)
  return ((i << shift) ^ (i >> (32 - shift))) % 2**32

def 				UpperCamelCase_    (    lowerCAmelCase__      :				bytes						)						->   Dict:

  """simple docstring"""




  lowerCAmelCase_   :				Optional[Any]								= preprocess(__a						)

  lowerCAmelCase_   :				List[str]								= [int(2**32 * abs(sin(i + 1						)						)						) for i in range(64						)]

  # Starting states
  lowerCAmelCase_   :				str								= 0x6_7_4_5_2_3_0_1
  lowerCAmelCase_   :				Dict								= 0xe_f_c_d_a_b_8_9
  lowerCAmelCase_   :				Union[str, Any]								= 0x9_8_b_a_d_c_f_e
  lowerCAmelCase_   :				List[str]								= 0x1_0_3_2_5_4_7_6

  lowerCAmelCase_   :				str								= [
      7,
      12,
      17,
      22,
      7,
      12,
      17,
      22,
      7,
      12,
      17,
      22,
      7,
      12,
      17,
      22,
      5,
      9,
      14,
      20,
      5,
      9,
      14,
      20,
      5,
      9,
      14,
      20,
      5,
      9,
      14,
      20,
      4,
      11,
      16,
      23,
      4,
      11,
      16,
      23,
      4,
      11,
      16,
      23,
      4,
      11,
      16,
      23,
      6,
      10,
      15,
      21,
      6,
      10,
      15,
      21,
      6,
      10,
      15,
      21,
      6,
      10,
      15,
      21,
  ]

  # Process bit string in chunks, each with 16 32-char words
  for block_words in get_block_words(__a						):
    lowerCAmelCase_   :				Union[str, Any]								= aa
    lowerCAmelCase_   :				List[str]								= ba
    lowerCAmelCase_   :				List[Any]								= ca
    lowerCAmelCase_   :				Tuple								= da

    # Hash current chunk
    for i in range(64						):
      if i <= 15:
        # f = (b & c) | (not_32(b) & d)     # Alternate definition for f
        lowerCAmelCase_   :				Dict								= d ^ (b & (c ^ d))
        lowerCAmelCase_   :				Any								= i
      elif i <= 31:
        # f = (d & b) | (not_32(d) & c)     # Alternate definition for f
        lowerCAmelCase_   :				Dict								= c ^ (d & (b ^ c))
        lowerCAmelCase_   :				Union[str, Any]								= (5 * i + 1) % 16
      elif i <= 47:
        lowerCAmelCase_   :				List[str]								= b ^ c ^ d
        lowerCAmelCase_   :				str								= (3 * i + 5) % 16
      else:
        lowerCAmelCase_   :				Dict								= c ^ (b | not_aa(__a						))
        lowerCAmelCase_   :				Dict								= (7 * i) % 16
      lowerCAmelCase_   :				Optional[int]								= (f + a + added_consts[i] + block_words[g]) % 2**32
      lowerCAmelCase_   :				Union[str, Any]								= d
      lowerCAmelCase_   :				str								= c
      lowerCAmelCase_   :				List[Any]								= b
      lowerCAmelCase_   :				Any								= sum_aa(__a    ,   left_rotate_aa(__a    ,   shift_amounts[i]						)						)

    # Add hashed chunk to running total
    lowerCAmelCase_   :				Optional[int]								= sum_aa(__a    ,   __a						)
    lowerCAmelCase_   :				Any								= sum_aa(__a    ,   __a						)
    lowerCAmelCase_   :				Tuple								= sum_aa(__a    ,   __a						)
    lowerCAmelCase_   :				Dict								= sum_aa(__a    ,   __a						)

  lowerCAmelCase_   :				str								= reformat_hex(__a						) + reformat_hex(__a						) + reformat_hex(__a						) + reformat_hex(__a						)
  return digest


if __name__ == "__main__":
     import doctest

     doctest.testmod()







'''simple docstring'''







from __future__ import annotations

from collections.abc import Iterator
from typing import Generic, TypeVar

__lowerCAmelCase         =    TypeVar("""T""")







class UpperCAmelCase__	( Generic[T]	):





  """simple docstring"""

  def __init__(		self      :     Tuple							,_a      :     T       ):


     '''simple docstring'''






     _a				:	List[str]			=   data
     _a				:	Node[T] | None			=   None


  def __str__(		self      :     Dict       ):


     '''simple docstring'''






     return F"""{self.data}"""







class UpperCAmelCase__	( Generic[T]	):





  """simple docstring"""

  def __init__(		self      :     Optional[int]       ):


     '''simple docstring'''






     _a				:	Node[T] | None			=   None


  def __iter__(		self      :     str       ):


     '''simple docstring'''






     _a				:	Tuple			=   self.top
     while node:
        yield node.data
        _a				:	int			=   node.next


  def __str__(		self      :     str       ):


     '''simple docstring'''






     return "->".join([str(_a       ) for item in self]       )


  def __len__(		self      :     Optional[Any]       ):


     '''simple docstring'''






     return len(tuple(iter(self       )       )       )


  def   __lowercase		(		self      :     str       ):


     '''simple docstring'''






     return self.top is None


  def   __lowercase		(		self      :     List[Any]							,_a      :     T       ):


     '''simple docstring'''






     _a				:	int			=   Node(_a       )
     if not self.is_empty():
        _a				:	Optional[Any]			=   self.top
     _a				:	List[str]			=   node


  def   __lowercase		(		self      :     Tuple       ):


     '''simple docstring'''






     if self.is_empty():
        raise IndexError('pop from empty stack'       )
     assert isinstance(self.top							,_a       )
     _a				:	List[Any]			=   self.top
     _a				:	int			=   self.top.next
     return pop_node.data


  def   __lowercase		(		self      :     List[str]       ):


     '''simple docstring'''






     if self.is_empty():
        raise IndexError('peek from empty stack'       )

     assert self.top is not None
     return self.top.data


  def   __lowercase		(		self      :     List[str]       ):


     '''simple docstring'''






     _a				:	Optional[int]			=   None


if __name__ == "__main__":
  from doctest import testmod

  testmod()



