Hacking Secret Ciphers with Python

(Ann) #1

36 http://inventwithpython.com/hacking


Email questions to the author: [email protected]


STRINGS AND WRITING


PROGRAMS


Topics Covered In This Chapter:
 Strings
 String concatenation and replication
 Using IDLE to write source code
 Saving and running programs in IDLE
 The print() function
 The input() function
 Comments


That's enough of integers and math for now. Python is more than just a calculator. In this chapter,
we will learn how to store text in variables, combine text together, and display text on the screen.
We will also make our first program, which greets the user with the text, “Hello World!” and lets
the user type in a name.


Strings


In Python, we work with little chunks of text called string values (or simply strings). All of our
cipher and hacking programs deal with string values to turn plaintext like 'One if by land,
two if by space.' into ciphertext like 'Tqe kg im npqv, jst kg im oapxe.'.
The plaintext and ciphertext are represented in our program as string values, and there’s a lot of
ways that Python code can manipulate these values.

Free download pdf