Hacking Secret Ciphers with Python

(Ann) #1
Chapter 6 – The Caesar Cipher 73

THIS IS MY SECRET MESSAGE.


If you see this error message when running the program:


Traceback (most recent call last):
File "C:\Python32\caesarCipher.py", line 4, in
import pyperclip
ImportError: No module named pyperclip


...then you have not downloaded the pyperclip module into the right folder. If you still
cannot get the module working, just delete lines 4 and 52 (which have the text “pyperclip” in
them) from the program. This will get rid of the code that depends on the pyperclip module.


Checking Your Source Code with the Online Diff Tool


To compare the code you typed to the code that is in this book, you can use the online diff tool on
this book’s website. Open http://invpy.com/hackingdiff in your web browser. Copy and paste
your code into the text field on this web page, and then click the Compare button. The diff tool
will show any differences between your code and the code in this book. This can help you find
any typos you made when typing out the program.


Practice Exercises, Chapter 6, Set A


Practice exercises can be found at http://invpy.com/hackingpractice 6 A.


How the Program Works............................................................................................................................................


Let’s go over exactly what each of the lines of code in this program does.


Importing Modules with the import Statement


caesarCipher.py



  1. Caesar Cipher




  2. http://inventwithpython.com/hacking (BSD Licensed)





  3. import pyperclip


Line 4 is a new kind of statement called an import statement. While Python includes many
built-in functions, some functions exist in separate programs called modules. Modules are
Python programs that contain additional functions that can be used by your program. In this case,
we’re importing a module named pyperclip so that we can call the pyperclip.copy()
function later in this program.

Free download pdf