As usual, create two directories for today's class. Create a
directory called lecture21
under activities, and
a directory called lab21
under labs.
You have been using Strings in your program since your first program. You have mostly been using them to label your print statements. Strings have a lot of built in functionality that we havve ignored up to this point. Today, we will explore this additional functionality, to see how we can build more interesting programs.
is_alpha.py
in your lecture21
directory. Create a function is_alphabetic
that takes
as a parameter a single character, and
returns True if and only if the character
parameter is an alphabetic character (a - z or A - Z). It should
return false otherwise. Use the
built-in ord
function to determine if a
character is alphabetic. Do not use any string methods.
Don't forget to define your test cases. Your program should execute your test cases automatically.
One of the biggest security vulnerabilities that web developers are constantly fighting is known as an SQL injection attack. In this attack, users of a website format input in such a way that their input gets interpreted as code in the web developers systems. The easiest mechanism for preventing such an attack is to remove the offending characters before they get used in the system somewhere.
For our purposes, we will consider any non-alphabetic character to
be "offending." Write a function strip_non_alpha
in a
file called input_sanitation.py
that
takes as a parameter a string, and returns a copy of the input
string with all non-alphabetic characters removed.
Passwords are possibly the most important way that individuals can ensure their own safety on the Internet. However, it is also typically the easiest thing for a hacker to figure out, or to get their hands on. This is simply because most Internet users choose incredibly weak passwords. Today, you will write a program that can generate passwords for individuals.
Create a file called password_generation.py
in
your lab21 directory. Your program should take as input from
the user the length of the password they want generated. Your
program should then print a random string of lower case characters of the
specified length.
Recall that you can use the random
module to generate
random numbers. Use the ord
and chr
functions generate random numbers in the ASCII range of the
lowercase characters, and convert them into a string.
Make sure you test your program well. How many test cases do you need? Include your test cases in your program file. Comment them appropriately.
When you have finished, create a tar file of your lab21
directory. To create a tar file, execute the following commands:
cd ~/cs120/labs tar czvf lab21.tgz lab21/
To submit your activity, go to cseval.roanoke.edu. You should
see an available assignment called Lab Assignment 21
. Only
one of your pair should submit your activity. Make sure both partners
are listed in the header of your files.
Do not forget to email your partner today's files!