96 http://inventwithpython.com/hacking
Email questions to the author: [email protected]
Encrypting with the Transposition Cipher
Topics Covered In This Chapter:
Creating functions with def statements.
main() functions
Parameters
The global and local scope, and global and local variables
The global statement
The list data type, and how lists and strings are similar
The list() function
Lists of lists
Augmented assignment operators (+=, -=, *=, /=)
The join() string method
Return values and the return statement
The special name variable
The Caesar cipher isn’t secure. It doesn’t take much for a computer to brute-force through all
twenty-six possible keys. The transposition cipher has many more possible keys to make a brute-
force attack more difficult.
Encrypting with the Transposition Cipher
Instead of replacing characters with other characters, the transposition cipher jumbles up the
message’s symbols into an order that makes the original message unreadable. Before we start
writing code, let’s encrypt the message “Common sense is not so common.” with pencil and