Cracking Codes with Python

Cracking Codes with Python
An Introduction to Building and Breaking Ciphers
Al Sweigart
November 2017, 480 pp.

Order now and get early access to the PDF ebook!
(What's Early Access?)
(Which chapters are available now?)

Get 30% off with the coupon code EARLYBIRD

In Cracking Codes with Python, you’ll learn how to program in Python while making and breaking ciphers, which are used to encrypt secret messages. (No programming experience required!)

After a quick crash course in programming, you’ll make, test, and hack classic cipher programs. You’ll begin with simple programs like the Caesar cipher and then work your way up to public key cryptography and the RSA cipher, which is used for modern secure data transmissions.

Each program comes with the full code and a line-by-line explanation of how things work. By book’s end, you’ll walk away with a solid foundation in Python and some crafty programs under your belt.

Learn how to:

  • Combine loops, variables, and flow control statements into real working programs
  • Use dictionary files to instantly detect whether text is English or nonsense
  • Create programs to test that the code you've written is working correctly
  • Write your own programming modules that you can import and use in other programs
  • Debug your programs and find common errors

Cracking Codes with Python is a chance to pick up some Python skills while getting a peek into the intriguing world of cryptography—what more could an aspiring hacker want?

Author Bio 

Al Sweigart is a professional software developer who teaches programming to kids and adults. His programming tutorials can be found at He is the author of Automate the Boring Stuff with Python, Scratch Programming Playground, and Invent Your Own Computer Games with Python.

Table of contents 


Chapter 1: Making Paper Cryptography Tools
Chapter 2: Installing Python
Chapter 3: Programming in the Interactive Shell (AVAILABLE NOW)
Chapter 4: Strings and Writing Programs (AVAILABLE NOW)
Chapter 5: The Reverse Cipher (AVAILABLE NOW)
Chapter 6: The Caesar Cipher (AVAILABLE NOW)
Chapter 7: Hacking the Caesar Cipher with Brute-Force (AVAILABLE NOW)
Chapter 8: Encrypting with the Transposition Cipher (AVAILABLE NOW)
Chapter 9: Decrypting with the Transposition Cipher (AVAILABLE NOW)
Chapter 10: Programming a Program to Test Your Program (AVAILABLE NOW)
Chapter 11: Encrypting and Decrypting Files (AVAILABLE NOW)
Chapter 12: Detecting English Programmatically (AVAILABLE NOW)
Chapter 13: Hacking the Transposition Cipher (AVAILABLE NOW)
Chapter 14: Making a Modular Arithmetic Module for the Multiplicative and Affine Ciphers
Chapter 15: Programming the Affine Cipher
Chapter 16: Hacking the Affine Cipher
Chapter 17: The Simple Substitution Cipher
Chapter 18: Hacking the Simple Substitution Cipher
Chapter 19: Programming the Vigenère Cipher
Chapter 20: Frequency Analysis
Chapter 21: Hacking the Vigenère Cipher
Chapter 22: The One-Time Pad Cipher
Chapter 23: Finding Prime Numbers
Chapter 24: Generating Keys for the RSA Cipher
Chapter 25: Public Key Cryptography and Programming the RSA Cipher

Appendix: Debugger