Question

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...

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 and numbers.
  • Try out capitalized versions of any of the above

For full credit, you must try out at least three approaches, such as those listed above

2.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
0 0
Add a comment Improve this question Transcribed image text
Answer #1

The required python script (guesspass.py):

import hashlib
import itertools

def guess_passwords():
  
   # 1. Hardcoded List approach
   # Make a list of possible passwords
   hardcoded_list = ["abcdefgh","abc1234","12345678","password","abcd123"]
   # Iterate through the list and guess each password
   for password in hardcoded_list:
       guess(password)

   # 2. Word file approach
   # Open file containing possible passwords (words.txt for example)
   file = open("words.txt","r")
   # Read through and make a file_words_list by splitting at a new line
   file_words_list = file.read().splitlines()
   # Iterate through the list and guess each password
   for password in file_words_list:
       guess(password)
   file.close()

   # 3. Four character length combinations
   # Make a list of possible character values in each password
   characters = ['!','@','#','$','%','^','&','*','(',')',':','[',']','a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
   # The itertools library provides a function which returns all possible combinations of a particular size from a list
   password_4len_list = [''.join(i) for i in itertools.product(characters,repeat=4)]
   # Iterate through the list and guess each password
   for password in password_4len_list:
       guess(password)

   # 4. Capitalized version approach for the hardcoded list, word file and all 4 character combinations
   # Open file containing words
   file = open("words.txt","r")
   # Make a word list out of it by splitting at new lines
   file_words_list = file.read().splitlines()
   # .upper() returns the upper cased string. Call it each for hardcoded, file and combinations list
   for password in hardcoded_list:
       guess(password.upper())
   for password in file_words_list:
       guess(password.upper())
   for password in password_4len_list:
       guess(password.upper())

def guess(guessed_password):
   # Generate the SHA256 Hash of the guessed password
   encrypted_guessed_password = hashlib.sha256(guessed_password).hexdigest()
   # Open the encrypted passwords file and create a list by splitting at each line
   file = open("encrypted_passwords.txt","r")
   encryted_passwords = file.read().splitlines()
   # Get no of lines in the files using length of list
   number_of_passwords = len(encryted_passwords)
   # Iterate through each password (each line in the encrypted passwords file)
   for i in range(number_of_passwords):
       # If match found...
       if encryted_passwords[i] == encrypted_guessed_password:
           print("Found match: "+guessed_password)
           print("Line number: "+str(i+1)) # Line number is index (i) + 1
           print("Encrypted value: "+encrypted_guessed_password)
   file.close()

if __name__ == "__main__":
   # If the python script is run, call guess_passwords()
   guess_passwords()

Sample "words.txt":

abc123
12345678
password

Sample "encrypted_passwords.txt"

16477688c0e00699c6cfa4497a3612d7e83c532062b64b250fed8908128ed548
983487d9c4b7451b0e7d282114470d3a0ad50dc5e554971a4d1cda04acde670b
e9cee71ab932fde863338d08be4de9dfe39ea049bdafb342ce659ec5450b69ae
03ac674216f3e15c761ee1a5e255f067953623c8b388b4459e13f978d7c846f4

Note: The lines in encrypted_passwords.txt correspond to the actual passwords "blue","abcd123","abcd1234" and "1234"

To run this: python guesspass.py

Sample Output:

Found match: abcd123
Line number: 2
Encrypted value: 983487d9c4b7451b0e7d282114470d3a0ad50dc5e554971a4d1cda04acde670b
Found match: blue
Line number: 1
Encrypted value: 16477688c0e00699c6cfa4497a3612d7e83c532062b64b250fed8908128ed548

Thank you.

Add a comment
Know the answer?
Add Answer to:
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...
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
  • 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...

  • Python Program Python: Number Guessing Game Write a Python function called "Guess.py" to create a number...

    Python Program Python: Number Guessing Game Write a Python function called "Guess.py" to create a number guessing game: 1. Function has one input for the number to Guess and one output of the number of attempts needed to guess the value (assume input number will always be between 1 and 1000). 2. If no number was given when the function was called, use random.randint(a,b) to generate a random number between a=1 and b=1000. You will also need to add an...

  • For this lab you will write a Java program that plays a simple Guess The Word...

    For this lab you will write a Java program that plays a simple Guess The Word game. The program will prompt the user to enter the name of a file containing a list of words. These words mustbe stored in an ArrayList, and the program will not know how many words are in the file before it starts putting them in the list. When all of the words have been read from the file, the program randomly chooses one word...

  • Do in Python please provide screenshots aswell. Here are the requirements for your game: 1. The...

    Do in Python please provide screenshots aswell. Here are the requirements for your game: 1. The computer must select a word at random from the list of avail- able words that was provided in words.txt. The functions for loading the word list and selecting a random word have already been provided for you in ps3 hangman.py. 2. The game must be interactive; the flow of the game should go as follows: • At the start of the game, let the...

  • Hey everyone, I need help making a function with this directions with C++ Language. Can you...

    Hey everyone, I need help making a function with this directions with C++ Language. Can you guys use code like printf and fscanf without iostream or fstream because i havent study that yet. Thanks. Directions: Write a function declaration and definition for the char* function allocCat. This function should take in as a parameter a const Words pointer (Words is a defined struct) The function should allocate exactly enough memory for the concatenation of all of the strings in the...

  • I need only one  C++ function . It's C++ don't write any other language. Hello I need...

    I need only one  C++ function . It's C++ don't write any other language. Hello I need unzip function here is my zip function below. So I need the opposite function unzip. Instructions: The next tools you will build come in a pair, because one (zip) is a file compression tool, and the other (unzip) is a file decompression tool. The type of compression used here is a simple form of compression called run-length encoding (RLE). RLE is quite simple: when...

  • For a C program hangman game: Create the function int play_game [play_game ( Game *g )]...

    For a C program hangman game: Create the function int play_game [play_game ( Game *g )] for a C program hangman game. (The existing code for other functions and the program is below, along with what the function needs to do) (Also the link to program files (hangman.h and library file) is below the existing code section. You can use that to check if the code works) What int play_game needs to do mostly involves calling other functions you've already...

  • In python please 6 annoying_int_sequence(n) In annoying_recursion.py, write the function annoying_int_sequence(n) which takes a single integer...

    In python please 6 annoying_int_sequence(n) In annoying_recursion.py, write the function annoying_int_sequence(n) which takes a single integer parameter (which must be non-negative). It must return a list of intgers. The contents of the integers are defined recursively. Basically, each version of this sequence is made up of the next-smaller one, repeated n times - and with the number n in-between. For instance, the sequence for n = 3 is: ???? 3 ???? 3 ???? Just drop in the the sequence for...

  • 0. Introduction. This involves designing a perfect hash function for a small set of strings. It...

    0. Introduction. This involves designing a perfect hash function for a small set of strings. It demonstrates that if the set of possible keys is small, then a perfect hash function need not be hard to design, or hard to understand. 1. Theory. A hash table is an array that associates keys with values. A hash function takes a key as its argument, and returns an index in the array. The object that appears at the index is the key’s...

  • Objectives You will implement and test a class called MyString. Each MyString object keeps track ...

    Objectives You will implement and test a class called MyString. Each MyString object keeps track of a sequence of characters, similar to the standard C++ string class but with fewer operations. The objectives of this programming assignment are as follows. Ensure that you can write a class that uses dynamic memory to store a sequence whose length is unspecified. (Keep in mind that if you were actually writing a program that needs a string, you would use the C++ standard...

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