Advertisement
Guest User

Untitled

a guest
Aug 20th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.24 KB | None | 0 0
  1. # verifykey.py
  2. # Version 1.0; current as of clue 4.
  3. import hashlib, binascii, os
  4.  
  5. # Honestly I don't know how these hashing functions work, just copied them from a Github post I found.
  6. def hash_password(password):
  7.     """Hash a password for storing."""
  8.     salt = hashlib.sha256(os.urandom(60)).hexdigest().encode('ascii')
  9.     pwdhash = hashlib.pbkdf2_hmac('sha512', password.encode('utf-8'),
  10.                                 salt, 100000)
  11.     pwdhash = binascii.hexlify(pwdhash)
  12.     return (salt + pwdhash).decode('ascii')
  13.  
  14. def verify_password(stored_password, provided_password):
  15.     """Verify a stored password against one provided by user"""
  16.     salt = stored_password[:64]
  17.     stored_password = stored_password[64:]
  18.     pwdhash = hashlib.pbkdf2_hmac('sha512',
  19.                                   provided_password.encode('utf-8'),
  20.                                   salt.encode('ascii'),
  21.                                   100000)
  22.     pwdhash = binascii.hexlify(pwdhash).decode('ascii')
  23.     return pwdhash == stored_password
  24.  
  25. # 0: 1; 1-2: 2; 3: 3; 4:4;
  26. # This list just holds all of the hashed keys so I can check if yours is right without revealing the key itself.
  27. keys = ['8b5b239a9a74f495279476a6df2cfaf87244e749a6b8ac645347161ced815f2d66453fe03e86b76ab3cabf7f436c3d128fd59ddc36d6dbb404ffe99893ad7d48ec8df1c36f281c203115b2d01137ee9f9e0ee550793259c1d3ea735616d3151b', '51582363ffc8aab41b679762f30e0e4ec6ede85fa95a7c7775f6709046755f88d5810eece5f96f94dcf8c223857fb78280eb06f44a05a80bd0f418f1f3b18a6175cab54e5a4e9330f9580fc14afe7c989f0981d995787af68c30337538b093bc', '60a4767d75781d980e765f633af218e0114b87143972a2bac7d99f6e7788778916b29c60bfe5967c41e9f5151733c5678cf526ab6f6a1e5cdf2532a9b8388b98df6b70999a29bf8598b1c7839ef4d6fe0801751c90dc6b9f838af19f48a725b7', 'ce5efbe33c42b5b598c83f3d694172fbafb35094653e2e6e7a750a525f1e0de25e28213a24984cb8d17bfb148bd1a735cfd93614e143b10664b073d11ff8aa2c2c27fe4d7738b800e0c0baa48cfac1edefd46f2dbb56f11c7a631515ab38ff9d', 'd95a95183b680b0a4a6c18565f011561e144adba3d635696c27cfd85d86ddd0bacd43049506fe03f5ea24c1a3a86a548a0c548245490be7d47fcf15efa81d8a101a9eab11d2e60239b0473d18eaeee0ee2335de74763c25da3e1006fed1bc3fa']
  28.  
  29. # While loops repeat whatever is inside them forever unless told otherwise
  30. while True:
  31.     match = False
  32.     # asks for text input and sets it as entry.
  33.     entry = input('Enter key to be verified: ')
  34.     # for loop: compares each key in the keys list(hashed keys)
  35.     for key in keys:
  36.         # if the hashed text entry equals the stored key...
  37.         if verify_password(key, entry):
  38.             match = True
  39.             # gets the index of the correct key(index is the position within the list, starting with 0 and counting up)
  40.             ind = keys.index(key)
  41.             # sets which step it matches based on its index. clean way to figure out which clue the key matches
  42.             if ind is 0:
  43.                 step = 1
  44.             elif ind is 1 or ind is 2:
  45.                 step = 2
  46.             elif ind is 3:
  47.                 step = 3
  48.             elif ind is 4:
  49.                 step = 4
  50.     # If there was a match: print correct statement; else: print wrong statement.
  51.     if match == True:
  52.         print('...Correct; ' + entry + ' matched with step ' + str(step) + '.')
  53.     else:
  54.         print('...Key ' + entry + ' not found.')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement