In: Computer Science
Generating secure password that you can remember, lab2pr0.py
It’s not easy
to come up with a secure password that one can actually remember.
One of the
methods proposed is to take a line of text and take first letter of
each word to form
a password. An extra step is substitute ”o” with 0, ”a” with ”@”,
and ”l” with
1. For instance, using ”Cookies and Code, let’s meet on Tuesdays”
would yield
”C@C,1m0T”. Write a program that asks the user to enter a phrase
and outputs
the password that is generated using these rules.
You can assume that the words in the phrase will be separated by a
single space or
a common punctuation sign such as ”.,?!;:” followed by a space.
use python
""" Step-1) define method password_generator with input text from user as parameter to it. Step-2)Split the words in the text based on white space using split(' ') method. Step-3) Add first letter of each word to the password , if the first letter is 'o'->'0', if it is 'a'->'@', if it is 'l'->'1'. Since words in the text are seperated by a single space or a common punctuation sign such as ”.,?!;:” followed by a space. And we have already splitted the text based on 'white space' , therefore we just need to check the last letter of each word for punctuation sign and include it in the password. '""" def password_generator(text): password = '' temp_list = list(text.split()) print(temp_list) for word in temp_list: if word[0] == 'o': password += '0' elif word[0] == 'l': password += '1' elif word[0] == 'a': password += '@' else: password += word[0] if word[-1] == ',' or word[-1] == ':' or word[-1] == '?' or word[-1] == '.'\ or word[-1] == ';' or word[-1] == '!': password += word[-1] return password if __name__ == '__main__': text = input('Enter text') print(password_generator(text))
If you have any doubts or want some modification in the code , just put the comment on the answer, i would be happy to help.