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
Code:
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
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...
PYTHON 1.Guessing many passwords: Write a function called guess_passwords. It doesn't take any arguments. It should use the function guess, trying out as many possible passwords as possible. Here are some methods you might try: Try out a hardcoded list of strings that you think people might use as passwords. Try out all words in the word file. Try out all character combinations of length 4 or less (or more if you don't mind waiting). Try out combinations of words...
Write a function called filter_crime_stats(stats,param,x,y) that takes a 2D list of crime stats, a string argument param from the set {YEAR, MONTH, DAY}, an integer start value x and an integer end value y as arguments, and returns the 2D list of crime stats containing the crime type, year, month, day, and neighbourhood of all crimes reported between the start value and the end value of the {YEAR/MONTH/DAY}. The value of param is not case sensitive. For example, Year, YEAR,...