Answered step by step
Verified Expert Solution
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 ENCRYPTIONKEY, and userspasses initialized. In the userspasses string, there is a # between user names and passwords; there is a between every username#password pair.
userspasses "donald#xgfcmickey#zygonsnow#smbpn
User names and encrypted passwords in the userspasses string are as follows:
duck mouse snow white
The program must also have the following functions:
islowerenglish:
This function takes a string variable as a parameter.
It checks if all characters in the string variable are English lowercase alphabetic
characters, ie 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.
encryptdecrypt:
This function receives three string parameters from the calling program: the password, key and key
This function encryptsdecrypts the password as follows: Each letter in the password is located in key Then the letter at the same position in key 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 key ENCRYPTIONKEY is passed to key and the password is duck
key "abcdefghijklmnopqrstuvwxyz"
key "qjfxnawmbucezhyiklopgrstvd"
The first letter in the password is d which is the fourth letter in key Therefore we find the fourth letter in key 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 key and ENCRYPTIONKEY is passed to key encryption is accomplished. Conversely, if ENCRYPTIONKEY is passed to key and ALPHABET is passed to key decryption is accomplished.
addaccount:
This functions takes parameters: userspasses, newusername, and newpassword.
It encrypts the new password using the encryptdecrypt function before
concatenating the username and password to the userspasses string.
It sends back the new userspasses string as its result.
retrievepassword:
This function takes parameters: userspasses and username.
It decrypts the password that is stored in userspasses for the specific username by
calling the encryptdecrypt function.
It returns the decrypted password.
getvalidinput:
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 islowerenglish 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.
main:
Here, the program asks the user for a valid username by calling the getvalidinput
function.
If the username exists in the userspasses variable, the program asks the user for the
password by calling the getvalidinput function again.
i If the password given by the user and the real password obtained by calling
the retrievepassword 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 userspasses variable, the program asks the user if she 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 getvalidinput function and adds the account to the userspasses string by calling the addaccount function and prints the resulting userspasses.
The program output should be exactly as follows bold entries are sample input:
Sample Output
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...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started