#!/usr/bin/env python # coding: utf-8 # # SAISOFT PYT-PR: Session 10 # # ### The Ecosystem includes Many Languages # # The Python ecosystem involves Python in using other languages and rule sets such as: # # * SQL (Structured Query Language) # * Regexes (Regular Expressions) # * Markdown (for Jupyter Notebooks) # * magic (% and %% inside Notebooks and I-Python) # * APIs (every library and framework comes with one) # * Sphinx (documentation generator, uses reStructured Text) # * JavaScript (used with web frameworks) # * Template Languages (example: Jinja) # * HTML / CSS (naturally) # * Widget Toolkits (more APIs for GUIs) # * IDEs (such as Spyder, Pycharm, Sublime Text, vi, emacs) # # and so much else. # Lets take a look at another Standard Library module and talk about what it does. # # Hash functions are not designed to preserve content. They don't encrypt. They're about associating some unique finger print with any hashable object. # In[ ]: import hashlib m = hashlib.sha256() m.update(b"Nobody inspects") m.update(b" the spammish repetition") m.digest() # Expected: #
# b'\x03\x1e\xdd}Ae\x15\x93\xc5\xfe\\\x00o\xa5u+7\xfd\xdf\xf7\xbcN\x84:\xa6\xaf\x0c\x95\x0fK\x94\x06'
# 
# # In[ ]: result = hashlib.sha256(b"Nobody inspects the spammish repetition").hexdigest() result # In[ ]: print("Digest size", m.digest_size) print("Block size ", m.block_size) # In class, we looked at a passwords database that doesn't save actual passwords, only hashes thereof. Even system administrators with the keys to the database, have no means to force a hash to run backwards to regain the phrase which was behind it. A hash is a one way street. # # ### LAB: # # Check the Python docs and run the above example with sha224 instead. Do you get past this assertion (unit test)? # In[ ]: # Uncomment me to check your result # assert result == 'a4337bc45a8fc544c03f52dc550cd6e1e87021bc896588bd79e901e2'