Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # verifykey.py
- # Version 1.0; current as of clue 4.
- import hashlib, binascii, os
- # Honestly I don't know how these hashing functions work, just copied them from a Github post I found.
- def hash_password(password):
- """Hash a password for storing."""
- salt = hashlib.sha256(os.urandom(60)).hexdigest().encode('ascii')
- pwdhash = hashlib.pbkdf2_hmac('sha512', password.encode('utf-8'),
- salt, 100000)
- pwdhash = binascii.hexlify(pwdhash)
- return (salt + pwdhash).decode('ascii')
- def verify_password(stored_password, provided_password):
- """Verify a stored password against one provided by user"""
- salt = stored_password[:64]
- stored_password = stored_password[64:]
- pwdhash = hashlib.pbkdf2_hmac('sha512',
- provided_password.encode('utf-8'),
- salt.encode('ascii'),
- 100000)
- pwdhash = binascii.hexlify(pwdhash).decode('ascii')
- return pwdhash == stored_password
- # 0: 1; 1-2: 2; 3: 3; 4:4;
- # This list just holds all of the hashed keys so I can check if yours is right without revealing the key itself.
- keys = ['8b5b239a9a74f495279476a6df2cfaf87244e749a6b8ac645347161ced815f2d66453fe03e86b76ab3cabf7f436c3d128fd59ddc36d6dbb404ffe99893ad7d48ec8df1c36f281c203115b2d01137ee9f9e0ee550793259c1d3ea735616d3151b', '51582363ffc8aab41b679762f30e0e4ec6ede85fa95a7c7775f6709046755f88d5810eece5f96f94dcf8c223857fb78280eb06f44a05a80bd0f418f1f3b18a6175cab54e5a4e9330f9580fc14afe7c989f0981d995787af68c30337538b093bc', '60a4767d75781d980e765f633af218e0114b87143972a2bac7d99f6e7788778916b29c60bfe5967c41e9f5151733c5678cf526ab6f6a1e5cdf2532a9b8388b98df6b70999a29bf8598b1c7839ef4d6fe0801751c90dc6b9f838af19f48a725b7', 'ce5efbe33c42b5b598c83f3d694172fbafb35094653e2e6e7a750a525f1e0de25e28213a24984cb8d17bfb148bd1a735cfd93614e143b10664b073d11ff8aa2c2c27fe4d7738b800e0c0baa48cfac1edefd46f2dbb56f11c7a631515ab38ff9d', 'd95a95183b680b0a4a6c18565f011561e144adba3d635696c27cfd85d86ddd0bacd43049506fe03f5ea24c1a3a86a548a0c548245490be7d47fcf15efa81d8a101a9eab11d2e60239b0473d18eaeee0ee2335de74763c25da3e1006fed1bc3fa']
- # While loops repeat whatever is inside them forever unless told otherwise
- while True:
- match = False
- # asks for text input and sets it as entry.
- entry = input('Enter key to be verified: ')
- # for loop: compares each key in the keys list(hashed keys)
- for key in keys:
- # if the hashed text entry equals the stored key...
- if verify_password(key, entry):
- match = True
- # gets the index of the correct key(index is the position within the list, starting with 0 and counting up)
- ind = keys.index(key)
- # sets which step it matches based on its index. clean way to figure out which clue the key matches
- if ind is 0:
- step = 1
- elif ind is 1 or ind is 2:
- step = 2
- elif ind is 3:
- step = 3
- elif ind is 4:
- step = 4
- # If there was a match: print correct statement; else: print wrong statement.
- if match == True:
- print('...Correct; ' + entry + ' matched with step ' + str(step) + '.')
- else:
- print('...Key ' + entry + ' not found.')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement