Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For this homework, you will be working on string manipulation in Python. Your task is to create a program that stores accounts as usernames and

For this homework, you will be working on string manipulation in Python. Your task is to create a program that stores accounts as usernames and passwords within a single string. The program encrypts passwords before storing them. The program will consist of various functions for retrieving passwords for a given username, verifying the correct passwords, and adding accounts.
You will get a starter file with functions and some variables (ALPHABET, ENCRYPTION_KEY, and users_passes) initialized. In the users_passes string, there is a # between user names and passwords; there is a * between every username#password pair.
users_passes = "donald#xgfc*mickey#zygon*snow#smbpn"
User names and (encrypted) passwords in the users_passes string are as follows:
duck mouse snow white
The program must also have the following functions:
1. is_lower_english:
This function takes a string variable as a parameter.
It checks if all characters in the string variable are English lowercase alphabetic
characters, i.e. all characters must be in the ALPHABET global variable.
It returns a Boolean value (True if all characters are English lowercase alphabetic
characters, False if not). User name
donald
mickey
Password
You have to add the parameters and return values to the functions defined in the starter code.
The pass statement in Python is a placeholder statement which is used when the syntax requires a statement, but you don't want to execute any code. It is a null operation -- when it is executed, nothing happens. It's often used as a placeholder indicating where code will eventually go, essentially leaving a function empty.
2. encrypt_decrypt:
This function receives three string parameters from the calling program: the password, key1 and key2.
This function encrypts/decrypts the password as follows: Each letter in the password is located in key1. Then the letter at the same position in key2 is found. This is the encrypted counterpart of that letter. All such letters are put together to construct the encrypted password. The resulting string is then sent back to the calling program as the result of this function.
For example, assume that ALPHABET is passed to key1, ENCRYPTION_KEY is passed to key2 and the password is duck.
key1= "abcdefghijklmnopqrstuvwxyz"
key2= "qjfxnawmbucezhyiklopgrstvd"
The first letter in the password is d, which is the fourth letter in key1. Therefore we find the fourth letter in key2, which is x; this is the encrypted version of d. We repeat this procedure for all other letters of the password duck to construct the encrypted string xgfc.
While calling this function, if ALPHABET is passed to key1 and ENCRYPTION_KEY is passed to key2, encryption is accomplished. Conversely, if ENCRYPTION_KEY is passed to key1 and ALPHABET is passed to key2, decryption is accomplished.
3. add_account:
This functions takes 3 parameters: users_passes, new_username, and new_password.
It encrypts the new password (using the encrypt_decrypt function) before
concatenating the username and password to the users_passes string.
It sends back the new users_passes string as its result.
4. retrieve_password:
This function takes 2 parameters: users_passes and username.
It decrypts the password that is stored in users_passes for the specific username by
calling the encrypt_decrypt function.
It returns the decrypted password.
5. get_valid_input:
This function takes a message string (question to be asked to the user) as a parameter from the calling program.
It asks the user for a string input x, which will be either a username or a password.
It checks if x comprise of lowercase English alphabetic characters by calling the is_lower_english function. As long as it is not, it prints out an error statement and asks the user for x again.
It sends back x as its result.
6. main:
Here, the program asks the user for a valid username by calling the get_valid_input
function.
If the username exists in the users_passes variable, the program asks the user for the
password by calling the get_valid_input function again.
i. If the password given by the user and the real password (obtained by calling
the retrieve_password function) are identical, the user will have
successfully logged in.
ii. Otherwise, the user will be told that the password is incorrect.
If the username does not exist in the users_passes variable, the program asks the user if s/he wants to add an account as either Y or N.
i. If the user answers with a string that starts with Y after converting the first letter to uppercase, the program asks the user for the username and password by calling the get_valid_input function and adds the account to the users_passes string by calling the add_account function and prints the resulting users_passes.
The program output should be exactly as follows (bold entries are sample input):
Sample Output 1
Enter your username: donald Enter your pas

Step by Step Solution

There are 3 Steps involved in it

Step: 1

Certainly Below is a Python program that fulfills the given requirements python ALPHABET abcdefghijk... 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

Step: 3

blur-text-image

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

Principles Of Managerial Finance

Authors: Lawrence J. Gitman, Chad J. Zutter

13th Edition

9780132738729, 136119468, 132738724, 978-0136119463

More Books

Students also viewed these Programming questions

Question

What is the shape of the chi-square distribution?

Answered: 1 week ago