Lab: Command-Line Tools and Exceptions
Due: Wednesday, October 7 at 11:59pm · Worth: 8 points
An exception lets a program respond when an operation fails. In this lab you’ll work on archive recovery and package a small command-line program called cowsay.
Start
Download and extract the starter ZIP. Open the inner lab-cli-tools folder in VS Code, then initialize and publish your repository as lab-cli-tools. Activate a Python environment, then run:
python -m pip install .
python -m pip install flake8Download the candidate password list using Download raw file, and save it as Ashley-Madison.txt beside the two practice ZIPs. Keep the starter’s packages = ["cowsay"] setting in pyproject.toml.
Install and recover
First edit cowsay/__main__.py to fix its formatting without changing its output. Then write the password-recovery code in password_cracker.py. The starter includes the known-password example as a runnable file, so you can inspect how extraction works before writing the loop.
Install and clean up Cowsay
The starter contains a working package with formatting problems. Use the packaging explanation and PEP 8 as references.
-
Install the supplied Cowsay package so the
cowsaycommand works outside its source folder. -
Preserve the command’s behavior: display the supplied message, its speech bubble, and the cow drawing.
-
Fix the supplied package’s formatting until
flake8 --isolated cowsayreports no errors. Reinstall after editing.
Recover the archive
Run the supplied open_archive.py on the known-password archive first. Then complete password_cracker.py. A password must be bytes, so strip each line’s newline and encode the string. Catch RuntimeError, zipfile.BadZipFile, and zlib.error around extraction. Use only the supplied practice archives. The exceptions reading explains how to continue after a failed attempt.
-
Read every line of
Ashley-Madison.txtinto a list namedpasswords. -
Try the candidate passwords against
whitehouse_secrets.zip. Continue after failed guesses and print the successful password. -
Extract the archive’s contents with the successful password. Stop after success.
-
Commit the recovered
whitehouse_secrets/whitehouse_secrets.txt.
Check and submit
Run these commands from lab-cli-tools:
flake8 --isolated cowsay
python -m pip install .
cowsay "recovery check"
python password_cracker.pyTry cowsay from another folder as well. Open the extracted secrets and check their contents. A failed extraction can leave a file behind, so its existence alone is not enough.
Commit and sync cowsay/, pyproject.toml, password_cracker.py, and whitehouse_secrets/whitehouse_secrets.txt. On Gradescope, choose GitHub and submit lab-cli-tools and the branch containing your work. The submission guide explains resubmission.