8.3 Cracking the Rail Fence
One of the programming problems in the Codes and Other Secrets chapter was to write a generalized version of the transposition cipher called the rail fence cipher. In that chapter, we used a two-rail fence with the odd and even characters placed into separate rails. In this section we will look at a brute-force technique to break this cipher. Let’s begin by reviewing the procedure for the rail fence.
The key to the rail fence cipher is the number of rails used. When you know the number of rails, you encrypt the message by filling the rails top to bottom and left to right. For example, let’s suppose we want to encrypt the message “new ipad coming tomorrow” using three rails.
Once we have constructed the rails, ...
Get Python Programming in Context, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.