Question

In: Computer Science

1. Lets start by creating a traditional random password composed of numbers, letters, and a few...

1. Lets start by creating a traditional random password composed of numbers, letters, and a few special characters.

letters = "abcdefghijklmnopqrstuvwxyz"
caps = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
numbers = "1234567890"

# Make an 8 letter password by combining characters from the three strings

2. Next you follow the XKCD model of selecting four random words and concatenating them together to for our password.

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']

# Make a four word password by combining words from the list of nouns, verbs and adjs


3. Of course that does not make the IT department of most colleges and businesses happy. They still want you to have at least one capital letter and a number in your password. We’ll learn more about this in a couple of chapters but it is easy to replace parts of a string with a different string using the replace method. For example "pool".replace('o', 'e') gives us peel Once you have your final password you can replace some letters with number substitutions. For example its common to replace the letter l with the number 1 or the letter e with the number 3 or the o with a 0. You can get creative. You can also easily capitalize a word using "myword".capitalize() Once you feel confident that you understand the code below you can use this activecode to make your password comply with standard procedures to include special characters.

word = "pool"
word = word.replace('o', 'e')
print(word)
word = word.capitalize()
print(word)

4.

Challenge

This last part goes beyond what you have covered in the book so far, but I’ll give you the extra code you need. You will probably be able to figure out what it does and this is kind of a fun preview of things to come.

Lets suppose you DO have a 4 character password composed only of lower case letters. How many guesses would it take you to guess the password? You can actually write a program to create a four character string and compare it to the known password. If we put this process inside a loop we can keep track and see how many guesses it takes us to find the matching password.

import random
import sys
sys.setExecutionLimit(60000) # 60 seconds
my_password = "abcd"
guess_num = 0
done = False
while not done:

guessed_pw = ""
# your code here

if guessed_pw == my_password:
print("found it after ", guess_num, " tries")
done = True

Solutions

Expert Solution

Thanks for the question, I have added comments for all the 4 sub questions. Let me know in case you have any questions or doubts.

============================================================================

letters = "abcdefghijklmnopqrstuvwxyz"
caps = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
numbers = "1234567890"
# Make an 8 letter password by combining characters from the three strings
import random
symbols=[]
for _ in range(3):
    symbols.append(random.choice([letter for letter in letters]))
    symbols.append(random.choice([letter for letter in caps]))
    symbols.append(random.choice([letter for letter in numbers]))
random.shuffle(symbols)
password = ''.join(symbols) # symbols will contain 9 symbols
password=password[1:] # we slicing and taking the last 8 symbols
print(password)

# 2
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']

dictionary_password=''
dictionary_password+=random.choice(nouns)
dictionary_password+=random.choice(adjs)
dictionary_password+=random.choice(nouns)
dictionary_password+=random.choice(verbs)

print(dictionary_password)

#3
dictionary_password=dictionary_password.title() # convert the first letter to uppercase
print(dictionary_password)
# replace the vowels with digits
dictionary_password=dictionary_password.replace('o','0')
dictionary_password=dictionary_password.replace('i','1')
dictionary_password=dictionary_password.replace('s','$')
dictionary_password=dictionary_password.replace('e','9')
dictionary_password=dictionary_password.replace('a','8')

print(dictionary_password)

# 4

my_password='zzzz'
guess_num=0
# we need 4 for loops for each letter combinations
# for every four letters we will form the 4 letter word
# and compare to the password we need to guess

for first in letters:
    for second in letters:
        for third in letters:
            for fourth in letters:
                # try all combinations of the letters
               
attempt=first+second+third+fourth
                guess_num+=1
                if attempt==my_password:
                    print('found it after ',guess_num,"tries")
                    break


Related Solutions

An 8-character password consists of four numbers (from 1 to 9) followed by two letters (from...
An 8-character password consists of four numbers (from 1 to 9) followed by two letters (from A to Z) followed by two more numbers (from 1 to 9). a) How many different passwords can be formed if letters and numbers can be repeated? b) How many different passwords can be formed that have no repeated number or letters?
roblem 1) Try creating 100 normally disributed random numbers with an average of 10 and standard...
roblem 1) Try creating 100 normally disributed random numbers with an average of 10 and standard deviation of 1. How close is the average to 10? How close is the standard deviation to 1? Problem 2) Try creating 100 normally disributed random numbers with a true average of 10 and true standard deviation of 1. What is the confidence interval for the measured average? Is it higher or lower than the confidence interval for 20 samples?
Problem 1) Try creating 100 normally disributed random numbers with an average of 10 and standard...
Problem 1) Try creating 100 normally disributed random numbers with an average of 10 and standard deviation of 1. How close is the average to 10? How close is the standard deviation to 1? Problem 2) Try creating 100 normally disributed random numbers with a true average of 10 and true standard deviation of 1. What is the confidence interval for the measured average? Is it higher or lower than the confidence interval for 20 samples?
JOAN+CAN=START Solve this addition problem by substituting numbers by the given letters, to find the value...
JOAN+CAN=START Solve this addition problem by substituting numbers by the given letters, to find the value of start. Each letter represents a unique digit
Create a program using Java. Create two different 3D arrays with random numbers. (lets name them...
Create a program using Java. Create two different 3D arrays with random numbers. (lets name them array1 and array 2) Add the two 3Darrays together and then get the average. Save the average on a separate 3D array.(lets name it array3) Then add array1 and array3 then get the average Save the average on a separate 3Darray(lets name it array 4) Then add array2 and array3 then get the average Save the average on a separate 3Darray (lets name it...
1)How many license plates are there if they start with three capital letters followed by 4...
1)How many license plates are there if they start with three capital letters followed by 4 digits from 0 to 9. (Note that letters and digits can be repeated? 2)In how many ways can 5 men and 5 women be arranged in a line if the line starts with a man, and the men and women alternate?
1. you learned that random numbers (or, at least, pseudorandom numbers) are essential in cryptography, but...
1. you learned that random numbers (or, at least, pseudorandom numbers) are essential in cryptography, but it is extremely difficult even for powerful hardware and software to generate them. Go online and conduct research on random number generators. What are the different uses of these tools besides cryptography? How do they work? Explain your answer using your own words in 4-5 paragraphs. 2 .Do you believe that all data should be encrypted? Many computing professionals think this is a good...
create two random numbers between 1 and 6. if when the sum of two numbers are...
create two random numbers between 1 and 6. if when the sum of two numbers are added togethere their sum is less than 5 or greater than 12, output to the console: "you win". if is not, output "you lose" C++
1.Your Username for your company computer is three letters followed by five single digit numbers. The...
1.Your Username for your company computer is three letters followed by five single digit numbers. The Letters can be repeated but the digits cannot be repeated. Find total possible number of usernames for your company"s computer system. 2.If a pair of fair dice is rolled find following probability that a number other than seven or eleven is rolled such that it is given that one of the two die is a two or a four.? 3.It is estimated that 2%...
Same topic: 1. Consider all passwords of length 10 made up of numbers, lower-case letters, and...
Same topic: 1. Consider all passwords of length 10 made up of numbers, lower-case letters, and upper-case letters (from the English alphabet). a) If you pick such a password at random, what is the likelihood that it contains exactly 5 lower-case letters? b) If you pick such a password at random, what is the likelihood that it contains at most 9 lower-case letters? 2. Suppose you’re an ornithologist who specializes in American crows (Corvus brachyrhynchos), and you’ve collected data on...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT