@extends('template') @section('title') Lab 9: Secret Message @stop @section('content') # Lab 09: Secret Message This part of the lab will give you some practice using the debugger and setting breakpoints. We covered these topics in an earlier lab, now it's important to use these tools to help you figure out what your code is doing.
 ## The Debugger
We first [introduced the debugger back in lab 02](/labs/lab02/debugger).
To briefly review how it works: When running in debug mode, you can step
through things one operation at a time, and Thonny will show you each
value that gets created, plus the values of all active variables. To
speed things up, you can double-click in the margin to set a
'breakpoint', which will cause Thonny to fast-forward to that point in
the code when you run the debugger, and each time you hit the `resume`
button. This screenshot shows how breakpoints are set:

This picture shows the debugger in action:

## Hidden code
You can read through and even edit the code in `messageDecoder.py`. But we have
not given you the code for `secrets.py`; instead we gave you
`secrets.pyc`, which lets Python use the code but is a bit harder for you
to read (the solutions will include the full `secrets.py` file).
To figure out what the mysterious secret functions are doing, you'll have
to observe their behavior. You could do this in the shell, but you can
also use the debugger to see what they do when they're used within
`messageDecoder.py`.
## Be careful
The `messageDecoder.py` file was designed to delete the encrypted message if the
wrong password is entered. You should be able to use the debugger to
prevent this from happening (just stop the program before that part
runs). To start with, set a breakpoint on line 53 of `messageDecoder.py` so that
the debugger will pause (and you'll have a chance to stop it) before
actually erasing the file.
Note that in case you do accidentally erase the file, you can always use
the `encrypted.txt.backup` file we've provided to restore it.
## The password file
The mystery program won't do anything if there's no password file
present. But what file is it looking for?
Your first task is to figure out the correct filename for the password
file. The easiest way to do this is to step through the code one
operation at a time in the part where it computes the password file name,
and then see what result it comes up with. See below if you need an extra
hint.
## The Debugger
We first [introduced the debugger back in lab 02](/labs/lab02/debugger).
To briefly review how it works: When running in debug mode, you can step
through things one operation at a time, and Thonny will show you each
value that gets created, plus the values of all active variables. To
speed things up, you can double-click in the margin to set a
'breakpoint', which will cause Thonny to fast-forward to that point in
the code when you run the debugger, and each time you hit the `resume`
button. This screenshot shows how breakpoints are set:

This picture shows the debugger in action:

## Hidden code
You can read through and even edit the code in `messageDecoder.py`. But we have
not given you the code for `secrets.py`; instead we gave you
`secrets.pyc`, which lets Python use the code but is a bit harder for you
to read (the solutions will include the full `secrets.py` file).
To figure out what the mysterious secret functions are doing, you'll have
to observe their behavior. You could do this in the shell, but you can
also use the debugger to see what they do when they're used within
`messageDecoder.py`.
## Be careful
The `messageDecoder.py` file was designed to delete the encrypted message if the
wrong password is entered. You should be able to use the debugger to
prevent this from happening (just stop the program before that part
runs). To start with, set a breakpoint on line 53 of `messageDecoder.py` so that
the debugger will pause (and you'll have a chance to stop it) before
actually erasing the file.
Note that in case you do accidentally erase the file, you can always use
the `encrypted.txt.backup` file we've provided to restore it.
## The password file
The mystery program won't do anything if there's no password file
present. But what file is it looking for?
Your first task is to figure out the correct filename for the password
file. The easiest way to do this is to step through the code one
operation at a time in the part where it computes the password file name,
and then see what result it comes up with. See below if you need an extra
hint.