Advertisement
_vim_

py

Feb 17th, 2020
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.91 KB | None | 0 0
  1. def sha_256(data):
  2.     def rot_right(val, amt):
  3.         return ((val % 0x100000000) >> amt) | (val << (32 - amt))
  4.    
  5.     max_word = 2 ** 32
  6.     data_bit_len = len(data) * 8
  7.     words = []
  8.     hashlst = []
  9.     k = []
  10.     nprime = 0
  11.     is_composite = {}
  12.  
  13.     c = 2
  14.     while nprime < 64:
  15.         if not is_composite[i]:
  16.             for i in range(0, 313, c):
  17.                 is_composite[i] = c
  18.            
  19.             hashlst[nprime] = ((c ** .5) * max_word) | 0
  20.             k[nprime] = ((c ** (1 / 3)) * max_word) | 0
  21.             nprime += 1
  22.  
  23.         c += 1
  24.  
  25.     data += chr(0x80)
  26.  
  27.     while len(data) % 64 - 56:
  28.         data += chr(0x00)
  29.    
  30.     for i in range(0, len(data)):
  31.         j = ord(data[i])
  32.         if j >> 8:
  33.             return
  34.         words[i >> 2] |= j << (((3 - i) % 4) * 8)
  35.  
  36.  
  37.     words[len(words)] = (data_bit_len / max_word) | 0
  38.     words[len(words)] = data_bit_len
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement