Nobody likes to change their password, and its always hard trying to come up with a new password. In this project, we'll solve that problem using a solution posed by the popular XKCD comic.
Create a new notebook for this project in Google Colab.
letters = "abcdefghijklmnopqrstuvwxyz" caps = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" numbers = "1234567890" special = "!?-%$#*~"
letters
,
caps
, numbers
, and special
strings that were defined above. One algorithm for doing this is as follows:
passwd1
, that will be used to hold the password and initialize it to
the empty string.
nouns = ['tissue', 'processor', 'headquarters', 'favorite', 'cure', 'ideology', 'funeral', 'engine', 'isolation', 'perception', 'hat', 'mountain', 'session', 'case', 'legislature', 'consent', 'spread', 'shot', 'direction', 'data', 'tragedy', 'illness', 'serving', 'mess', 'resistance', 'basis', 'kitchen', 'mine', 'temple', 'mass', 'dot', 'final', 'chair', 'picture', 'wish', 'transfer', 'profession', 'suggestion', 'purse', 'rabbit', 'disaster', 'evil', 'shorts', 'tip', 'patrol', 'fragment', 'assignment', 'view', 'bottle', 'acquisition', 'origin', 'lesson', 'Bible', 'act', 'constitution', 'standard', 'status', 'burden', 'language', 'voice', 'border', 'statement', 'personnel', 'shape', 'computer', 'quality', 'colony', 'traveler', 'merit', 'puzzle', 'poll', 'wind', 'shelter', 'limit', 'talent']
verbs = ['represent', 'warm', 'whisper', 'consider', 'rub', 'march', 'claim', 'fill', 'present', 'complain', 'offer', 'provoke', 'yield', 'shock', 'purchase', 'seek', 'operate', 'persist', 'inspire', 'conclude', 'transform', 'add', 'boast', 'gather', 'manage', 'escape', 'handle', 'transfer', 'tune', 'born', 'decrease', 'impose', 'adopt', 'suppose', 'sell', 'disappear', 'join', 'rock', 'appreciate', 'express', 'finish', 'modify', 'keep', 'invest', 'weaken', 'speed', 'discuss', 'facilitate', 'question', 'date', 'coordinate', 'repeat', 'relate', 'advise', 'arrest', 'appeal', 'clean', 'disagree', 'guard', 'gaze', 'spend', 'owe', 'wait', 'unfold', 'back', 'waste', 'delay', 'store', 'balance', 'compete', 'bake', 'employ', 'dip', 'frown', 'insert']
adjs = ['busy', 'closer', 'national', 'pale', 'encouraging', 'historical', 'extreme', 'cruel', 'expensive', 'comfortable', 'steady', 'necessary', 'isolated', 'deep', 'bad', 'free', 'voluntary', 'informal', 'loud', 'key', 'extra', 'wise', 'improved', 'mad', 'willing', 'actual', 'OK', 'gray', 'little', 'religious', 'municipal', 'just', 'psychological', 'essential', 'perfect', 'intense', 'blue', 'following', 'Asian', 'shared', 'rare', 'developmental', 'uncomfortable', 'interesting', 'environmental', 'amazing', 'unhappy', 'horrible', 'philosophical', 'American']
nouns
, verbs
, and
adjs
lists above. The algorithm to do this is very
similar to the one for creating the 8-character password. Store the password in a new variable,
passwd2
.
len
function to help you
determine these sizes.)
password2
, create
a boolean variable named containsCap
and initialize it
to False
.
passwd3
, for the new password you are going to
create and initialize it to the password you just created. (Hint: Your code would look like
passwd3 = passwd2
)
caps
string (from above).) If it is, set your boolean
variable to be True
.
containsCap
is still
False
), we now need to replace a random character of
our password with a capital letter. Create a random number for the
position of the character in the password to be replaced. (This
would be a number between 0 and the length of the password.)
person
, defined by
we could replace the 'a' with an 'i' to make the word "biker" by doing the following:person = "baker"
The first term in that sum,newPerson = person[:1] + "i" + person[2:]
person[:1]
, takes all
of the characters from the beginning of the string, up to, but
not including the character at position 1. So this gives us the
substring "b". We then concatenate the "i", and then
concatenate the rest of the original word. The last term,
person[2:]
, gives all the characters from position 2 to
the end of the string, giving us the substring "ker".
Using the random number you generated in the previous step, replace the letter of your password in that position with the corresponding capital letter. You will need to use thenewPerson = person[:-1] + "d"
index()
function to
determine where in the alphabet the letter to be replaced
is. For example, if the lowercase "m" in the word
"pumpkin" is to be replaced with a capital "M", the code
might look something like the following:
The output from this code segment should beword = "pumpkin" letterToBeReplaced = word[2] positionInAlphabet = letters.index(letterToBeReplaced) newWord = word[:2] + caps[positionInAlphabet] + word[3:] print(newWord)
Print out your password to check that it looks the way you expect at this point.puMpkin
while
loop here. See Sections 14.2 and 14.3 in the
Runestone book for more information on
while
loops.)
numbers
list.
letters
. This should be a string containing the
26 lower case letters.
You should print the password and run this code to verify it creates a different 4-letter password each time. Then comment out the print statement.my_password="" for i in range(4): randNum = random.randint(0,25) randLetter = letters[randNum] my_password += randLetter
password_guess
, and
initialize it to the empty string.
for
loops to go through all possible
4-letter combinations which we will compare to the generated
4-letter password. Each loop will have the same
structure:
wherefor char1 in letters
char1
is replaced with char2
in
the second loop, char3
in the third loop, and so
on. Write the code for these loops.
password_guess
the concatenation of
char1
, char2
, char3
, and
char4
.
When you are satisfied your code is working properly, submit your notebook via Kit. Your Python code will be graded on the basis of style as well as correctness. Your code should include appropriate comments. (Comments before code sections, name, date, program description, assistance statement at the beginning of the file, etc.) Variable names should be descriptive.