Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please use python to do this All the files are in this folder https://drive.google.com/open?id=0BzoFdHKM0HX5M24yc2xxWXNpWTA CMPUT 175 LAB 7 Tasks: 1. In the remove_non_letters function,

Please use python to do this

All the files are in this folder

https://drive.google.com/open?id=0BzoFdHKM0HX5M24yc2xxWXNpWTA

""" CMPUT 175 LAB 7

Tasks: 1. In the remove_non_letters function, remove all characters in the string that are not letters, convert the string into lowercase and return the resulting string

2. In load_dictionary function, read a word corpus and return a dictionary whose keys are the words in the file and the values are the counts of the word

3. In load_password function, read a file which contains probable passwords and return them in a list

4. In get_english_percentage function, count the percentage of words in the message that appear as keys in the dictionary

5. In print_counts function, for each word of the decrypted message, print the number of times the word was in the corpus using the dictionary

6. In the main function, find the password that yields the highest percentage of English words in the decoded message.

7. In the main function, print the counts of each of the words in the message """

from sys import exit from sub import *

def remove_non_letters(word): """ TODO takes a string, removes all characters in the string that are not letters (i.e. numbers, special characters, spaces), converts the string into lowercase and returns the resulting string

Arg: word - string

Return: a lowercase string without numbers, special characters and spaces """ pass

def load_dictionary(filename): """ TODO Open the file specified as "filename" in only-read mode. It is assumed that "filename" is a corpus with multiple words per line. Return a dictionary whose keys are the words in the file and the values are the counts of the word. If a word has not yet been encountered, set its count to 1; otherwise increment the count by 1. Make sure for each word, you remove end-of-line characters and punctuation using remove_non_letters function before you add the word to the dictionary.

Arg: filename - the file which cotains the word corpus

Return: my_dictionary - keys are the words, values are the counts of the word """

my_dictionary = {}

return my_dictionary

def load_passwords(filename): """ TODO Open the file specified as "filename" in only-read mode. It is assumed that "filename" contains probable passwords. Add all the probable passwords in a list and return the list

Arg: filename - the file which contains probable passwords

Return: passwords - a list of probable passwords """

passwords = []

return passwords

def get_english_percentage(message, dictionary): """ TODO Count the percentage of words in the message that appear as keys in the dictionary. Make sure that for each word in the message, you call remove_non_letters function

Arg: message - a decrypted string Arg: dictionary - keys are the words, values are the counts of the word

Return: float - percentage of english words in the message

""" english_percentage = 0.0

return english_percentage

def print_counts(message, dictionary): """ TODO looks at each word in the message, finds its count and prints a statement: "wordX was seen y times". If the word is not in the dictionary print "wordX was not seen" Make sure that for each word in the message, you call remove_non_letters function

Arg: message - the decrypted string Arg: dictionary - keys are the words, values are the counts of the word """ print ('WORD COUNT:')

def main():

# The goal of this lab is to decrypt the encrypted message enc_mess enc_mess = 'qrt qout pagj ke ajqtffagtjst ap jkq cjkwftngt iuq ahdgajdqakj'

""" TODO: wells.txt is the text of a novel. Unlike a wordlist, it contains multiple counts of many of the words. Implement the loadDictionary function. which reads wells.txt file, stores each word in a dictionary that keeps track of the count of each word and returns the dictionary """ english_dictionary = load_dictionary('wells.txt')

""" TODO: probable_passwords.txt contains possible passwords which could decrypt enc_mess. Implement the loadPasswords functions which reads probable_passwords.txt, stores each password in a list and return the list """ probable_passwords = load_passwords("probable_passwords.txt")

""" TODO: Find the password that yields the highest percentage of English words in the decoded message. """ max_percentage = 0 max_password = '' max_decrypted_mess = '' # for password in probable_passwords: # key = genKeyFromPass(...) # decrypted_mess = substitutionDecrypt(enc_mess,key) # Determine the english percentage for the decrypted message # And update appropriate variable to find the password which # results in a decypted message with highest english percentage

""" Print the identified password, the decoded message, the percentage of english words to decimal places and the counts of each of the words in the message """ print ("Identified Password: %s " % max_password) print ("Decoded message: %s " % max_decrypted_mess) print ("English word percentage: %.2f " % max_percentage)

""" TODO: Implement the printCounts function which prints the count of each word of the decrypted message in the dictionary constructed from wells.txt """ print_counts(max_decrypted_mess, english_dictionary)

if __name__ == "__main__": main()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database Management Systems

Authors: Mark L. Gillenson

2nd Edition

0470624701, 978-0470624708

Students also viewed these Databases questions

Question

Explain how to reward individual and team performance.

Answered: 1 week ago