Advertisement
rfmonk

hashlib_update.py

Jan 31st, 2014
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.65 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. # this is from The Python
  4. # Standard Library by example
  5. # ISBN13: 9780321767349
  6.  
  7. import hashlib
  8.  
  9. from hashlib_data import lorem
  10.  
  11. h = hashlib.md5()
  12. h.update(lorem)
  13. all_at_once = h.hexdigest()
  14.  
  15.  
  16. def chunkize(size, text):
  17.     "Return parts of the text in size-based increments."
  18.     start = 0
  19.     while start < len(text):
  20.         chunk = text[start:start + size]
  21.         yield chunk
  22.         start += size
  23.     return
  24.  
  25. h = hashlib.md5()
  26. for chunk in chunkize(64, lorem):
  27.     h.update(chunk)
  28. line_by_line = h.hexdigest()
  29.  
  30. print 'All at once  :', all_at_once
  31. print 'Line by line :', line_by_line
  32. print 'Same         :', (all_at_once == line_by_line)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement