Hacking Secret Ciphers with Python

(Ann) #1
Chapter 2 – Downloading and Installing Python 21

You can tell when a new line starts by looking at the line numbers on the left side of the code.
The example below has only two lines of code, even though the first line is too long to fit on the
page:



  1. print('This is the first line! xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    xxxxxxxxxxxxxx’)

  2. print('This is the second line!')


Tracing the Program Online


Tracing a program means to step through the code one line at a time, in the same way that a
computer would execute it. You can visit http://invpy.com/hackingtraces to see a trace through of
each program in this book. The traces web page has notes and helpful reminders at each step of
the trace to explain what the program is doing, so it can help you better understand why these
programs work the way they do.


Checking Your Typed Code with the Online Diff Tool


Although it is very helpful to learn Python by typing out the source code for these programs, you
may accidentally make typos that cause your programs to crash. It may not be obvious where the
typo is.


You can copy and paste the text of your typed source code to the online diff tool on the book’s
website. The diff tool will show any differences between the source code in the book and the
source code you’ve typed. This is an easy way of finding any typos in your programs.


The online diff tool is at this web page: http://invpy.com/hackingdiff. A video tutorial of how to
use the diff tool is available from this book’s website at http://invpy.com/hackingvideos.


Copying and Pasting Text


Copying and pasting text is a very useful computer skill, especially for this book because many of
the texts that will be encrypted or decrypted are quite long. Instead of typing them out, you can
look at electronic versions of the text on this book’s website and copy the text from your browser
and paste it into IDLE.


To copy and paste text, you first need to drag the mouse over the text you want to copy. This will
highlight the text. Then you can either click on the Edit ► Copy menu item, or on Windows
press Ctrl-C. (That’s press and hold the Ctrl button, then press C once, then let go of the Ctrl
button.) On Macs, the keyboard shortcut is Command-C (the ⌘ button). This will copy the
highlighted text to the computer’s memory, or clipboard.

Free download pdf