cmsc 201 lab 3
Download
Skip this Video
Download Presentation
CMSC 201 – Lab 3

Loading in 2 Seconds...

play fullscreen
1 / 16

CMSC 201 – Lab 3 - PowerPoint PPT Presentation


  • 128 Views
  • Uploaded on

CMSC 201 – Lab 3. Strings. Overview. Objectives for today\'s lab: Obtain experience using strings in Python, including looping over characters in strings and conversion from ASCII

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' CMSC 201 – Lab 3' - dolph


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
overview
Overview
  • Objectives for today\'s lab:
    • Obtain experience using strings in Python, including looping over characters in strings and conversion from ASCII
    • Create a program that uses string operations to generate random passwords based on some of the password rules used at UMBC
simplified umbc password rules
Simplified UMBC Password Rules

May only contain printable characters (alphanumeric and symbols -- no spaces or "control" characters)

Must be at least 8 characters in length

Must include at least one upper case, lower case, and one non-alphabetic character

Must not contain three or more recurring characters. (such as \'sss\')

program outline
Program Outline
  • Required Code
    • Implement Rules 1-2
    • Print the new random password
  • Bonus Code
    • Implement Rule 3
  • Challenge
    • Implement Rule 4
required 0 setup
Required 0: Setup

The first step is to create a lab3 folder in your cs201/labs directory

From your home directory:

cd 201/labs

mkdir lab3

cd lab3

emacs lab3.py &

required 0 setup1
Required 0: Setup

Edit the lab3.py to look like the following:

# File: lab3.py

# Written by: YOUR NAME HERE

# Date: DATE HERE

# Section: ?

# Email: [email protected]

# Description: Lab 3, Random Password Generator

import random

def main():

#put code here

main()

required 0 ascii codes
Required 0: ASCII Codes
  • First, you need to familiarize yourself with the ASCII codes.
    • http://www.ascii.cl/
      • Ignore the column called Hex – use the column called ASCII
    • There is a 1-to-1 relationship between an ASCII code and the letter it represents
    • Find which codes are printable (valid chars)
    • Find which codes are numeric chars
    • Find which codes are special chars
    • Find which codes are lower case chars
    • Find which codes are upper case chars
required 1 pseudocode
Required 1: Pseudocode

create a new variable to hold the password

loop 8 times

generate random number in the printable char range

save it into a variable

turn the number into a character

add the new char to the end of the password string

print new password

required 2 compututations
Required 2: Compututations
  • Generate a random ASCII numeric code
    • random.randrange(a, b) will generate and return a random, integer value in the range a - b
      • Assign the value that was returned to a new variable
  • Convert the random number to a character value
    • chr( variable) takes an integer value and returns a character
      • Use the random number from above in the chr( ) function
      • Assign the value that was returned to a new variable
  • Add the new char to the end of the password
    • Use + to concatenate
      • string_var = string_var + new_character_var
required output
Required: Output
  • Print the new password

travis-laptop-2% python lab3.py

$d5iDmK#

bonus description
Bonus: Description
  • Bonus Code

Rule 3:

Password must include at least one upper case, lower case, and one non-alphabetic character

    • Change the for-loop into a while-loop
      • Continue to add characters to the password until there are enough of the right kinds of characters (with a minimum of 8)
bonus psuedocode
Bonus: Psuedocode

set counter variables to 0

set done condition variable to false

loop while done is false

generate random number

turn number into a character and add to password

increment counts of the different types of chars

if all the counts fulfill rules 1-3

set done condition variable to true

print new password

bonus initialization
Bonus: Initialization
  • Create variables to keep track of how many characters there are of each type.
    • You will need variables for uppercase, lowercase, and non-alphabetic
    • Make sure to give them appropriate names
    • Start counting at 0
  • Create a boolean variable to flag whether the password fulfills all the rules
    • The flag will be false initially
bonus while loops
Bonus: while loops

Loop while a condition is true

set condition to true

# execute stmts in loop while a condition is true

while (condition is true):

# execute 1 or more statements

# at some point, make condition false

set condition to false

bonus computations
Bonus: Computations
  • Loop until the password fulfills all the rules
    • Generate a random printable character
    • Increment the counter for the type of character that it is
    • Add the character to the password
    • If the password fulfills all the rules, set the flag to true
challenge
Challenge
  • Implement Rule 4
    • Must not contain three or more recurring characters
      • such as \'sss\'
ad