|Cracking Codes with Python|
Author: Al Sweigart
This is an interesting book, practical, about Python and codes, but before you buy it there are some things you need to know otherwise you might be disappointed. This is not the exciting dive into spies and code that you might expect. It is a mixture of a Python primer with an in-depth look at some very simple coding methods and a quick look at a more advanced code at the end of the book. If you are wanting to learn Python then there are better routes to achieve your goal. If you are wanting to learn about code then there are better books devoted to that topic that don't involve you in learning Python.
What all this means is that to like this book you need to want to learn some Python and play around with examples involving mostly simple encryption methods. You also need to be aware that while the book does spend quite a bit of space on explaining very simple Python commands, the examples very quickly grow to be fairly large and complicated. Personally, I don't think that such semi-real examples involving so much string manipulation are suitable for explaining programming concepts to the beginner - you might disagree. This is a book that attempts to introduce Python its readers, but hampers itself by having to use examples from a particular application area, whether or not they are suitable for the readers stage of development.
The book starts off with three chapters mostly on getting started with Python. Chapter 4 introduces the first cipher, the reverse cipher, which is an example of why this approach isn't a good idea if you want to learn programming. The reverse cipher simply reverses the order of the characters in a string. The method used is a for loop that counts backwards, but of course you could use a simpler for loop that counts forwards as long as you are prepared to point out which end of the string you add the next character to. My point is that there are many ways to reverse a string and so its not a good starting point for a beginner. This cipher would be better left until the beginner has had some time to let the idea of for loops sink in and mature. Chapter 5 is on the Caesar cipher, the first practical cipher in a historical sense. After implementing it Chapter 6 moves on to implement a brute force attack. Next we have a transposition cipher and its decryption in chapters 7 and 8.
At this point we take a small break from different types of ciphers and look at how to test a program, in Chapter 9, working with files, in Chapter 10, and in Chapter 11, using a dictionary to detect when a string is probably in English which indicates that you might have decrypted a message. With this explained, we can now return to the transposition cipher and write a program to crack it, which is tackled in Chapter 12.
The next three chapters prepare the ground for and implement the Affine Cipher and crack it. This needs modular arithmetic which is introduced in a simple way. Chapters 16 and 17 implement and crack the substitution cipher. Chapter 18 explains the well-known Vigenere cipher and chapters 19 and 20 explain frequency analysis and how to hack the Vigenere cipher.
The final four chapters deal with basically uncrackable codes. Chapter 21 implements a one time pad cipher, Chapter 22 explains how to find prime numbers, Chapter 23 is about generating keys for a public key cipher and Chapter 24 implements it. At this stage things are so mathematical that you will find that much is beyond the scope of the book and you are simply asked to use a supplied function without any deep explanation. I can't really see how the material could have been explained unless a lot more math was employed. At this point I also cannot see that the programs are going to be useful to a Python beginner.
This book is a very basic introduction to cryptography. It has a drawing of an Enigma coding machine on the cover, but it doesn't cover anything so complicated and it doesn't really explain much of the only usable cryptography systems it introduces towards the end. The cryptosystems that are well explained aren't much more than the sort of thing introduced to school children to try and get them interested in math.
What is interesting is the way that some of the surrounding tools are explained, in particular the use of a dictionary to detect when a code has been broken. But as they say, no real codes were broken in the making of this book.
The other aspect of the book, teaching Python, is made harder by the subject matter used to motivate it. The sort of complicated string manipulations needed to implement cryptographic algorithms quickly get well beyond what a beginner can cope with and many subtle points simply have to be ignored. Quite often the reader is simply told to use a supplied function and not worry about how it is implemented. Then there is the small matter that a huge part of the Python language isn't included at all - no objects, methods or properties.
I don't think that this book is suitable for everyone. If you are at the right level for the Python it presents and are happy just getting the flavour of cryptography then you might be the right reader.
|Last Updated ( Saturday, 28 September 2019 )|