Cracking Codes with Python

Cracking Codes with Python
An Introduction to Building and Breaking Ciphers
Al Sweigart
January 2018, 440 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 

Introduction (AVAILABLE NOW)

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

Appendix: Debugging Python Code