Question

Guessing one password: write a function called guess that takes a string (a guessed password) as an argument and prints out matching information if its encrypted string matches any of the strings in t...

Guessing one password: write a function called guess that takes a string (a guessed password) as an argument and prints out matching information if its encrypted string matches any of the strings in the encrypted password file. When you write the function, you may hardcode the name of the password file.

Here is an example run:

   >>> guess("blue")
   Found match: blue
   Line number: 1
   Encrypted value: 16477688c0e00699c6cfa4497a3612d7e83c532062b64b250fed8908128ed548

You will want to use the encrypt function presented in class:

import hashlib

def greeting(uname):
greet_message = "Hey there " + uname + "!"
return greet_message

def longest(word_list):
'''returns the longest word in word_list,
the first if there are several'''

longest_so_far = ""
for word in word_list:
if len(word) > len(longest_so_far):
longest_so_far = word
return longest_so_far

def encrypt(password):
encrypted_pwd = hashlib.sha256(password.encode()).hexdigest()
return encrypted_pwd

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code:

1 import sys 2 import os 3 import hashlib 4 def encrypt(password): encrypted_pwd hashlib.sha256 (password.encode()).hexdigest

Sample output:

Content of test.txt file:

16477688c0e00699c6cfa4497a3612d7e83c532062b64b250fed8908128ed548
6b4f36d8805a243e2d880036398724b6e4f4fb9998dbccae74685a0be9e0e599
b1f51a511f1da0cd348b8f8598db32e61cb963e5fc69e2b41485bf99590ed75a

Output:

radas-macOS:Desktop radas$ python a.py
Enter guess
blue
Found match: blue
Line number: 1
Encrypted value: 16477688c0e00699c6cfa4497a3612d7e83c532062b64b250fed8908128ed548

Add a comment
Know the answer?
Add Answer to:
Guessing one password: write a function called guess that takes a string (a guessed password) as an argument and prints out matching information if its encrypted string matches any of the strings in t...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT