Much of the work of enciphering and deciphering is algorithmic: the same predictable steps, done over and over. Tasks like these are perfect for a computer. Instead of working through them with pencil and paper, we’ll write instructions in Python and let the computer carry them out.
To begin, let’s get the basics of Python under our belt. Like a spoken language, Python has grammar rules, and instructions must follow them exactly for the computer to make sense of them. These rules are called the syntax of the language. People can usually understand a sentence with a grammar mistake in it. Computers can’t. The syntax must be exactly right for the computer to understand the task you’ve asked it to do.
In This Section¶
Using Python as a calculator, including the % operator that nearly every cipher uses.
Integers, floats, strings and booleans, and converting between them.
Giving names to values.
Working with text.
Asking Python true-or-false questions.
Making decisions with if, elif and else.
Our first cipher program.