"Cracking Codes with Python" is outstanding, but with caveats
Anyone used the books "cracking codes with python" and "learn to automate the boring stuff with python" to get started?
How to make my Python password cracker operate more efficiently? - Stack Overflow
Is is worth working through the book "Cracking Codes with Python" for expanding my knowledge towards cryptography, or are there better alternatives?
It's a good start, but you shouldn't spend too much time on it. Take it and go through in a decent pace, because the stuff before Chapter 21 is cool to know but not at all relevant in the real world.
It's a good book for really basic introduction, but you should go to something else imemdiately after.
More on reddit.comAfter 30 years of ignoring Python, I finally decided that I really should make an effort to learn it. Now I am probably not the intended audience, as I have some experience programming in lots of languages (though am not really an expert in any) and I know a thing or two about Cryptography. So I thought that working through this would be a way to get started as well as use of StackExchange and the Python docs.
Too ambitious in parts?
There are parts that I think may be overly ambitious to include in something like this in a self-guided context. In particular chapter 20, Hacking the Vigenère Cipher. I am familiar with the methods used break Vigenère (though I have never coded them) and had considered myself fairly comfortable with associative arrays ("dictionaries" to you young folk). But there was just a lot going on.
When I looked back over the text to see what could be improved for this chapter, I really didn't find anything. The explanations are excellent and broken up into exactly the right sized pieces, with appropriate reminders of where those pieces will fit. The walk through in the REPL is absolutely necessary here. My guess is that chapter is going to be discouraging unless the reader is part of a class or group working through the book.
Some of the difficulty may have been that with the ePub, I wasn't really seeing the diagrams well. (I'm old, my vision is failing, I use big text).
In Chapter 24, Programming the Public Key Cipher, I wonder if the encoding/decoding (not encrypting/decrypting) of text to and from big integers could have been more thoroughly factored out (as into a separate module).
Excellent discussion of Cryptography (for the purpose)
Many books or tutorials of this nature can leave people with dangerous ideas about cryptography. This book did not. Hacking the Simple Substitution Cipher communicates well that key space is not everything. The repeated warnings about "textbook RSA" were very welcome. The illustration of statistical attacks (without actually getting distracted by having to teach statistics) is really import. And the general explanations of cryptographic concepts was far better than I had expected. I absolutely loved the chapter epigrams and the choice to sample text.
The hard choices
In anything like this, the author has to make hard choices about what not to teach. I knew (as an experienced programmer) that os.sys.exit() is not really the way to handle errors such as invalid input and the like. So I read on my own how to raise exceptions in Python. But the author has to make choices about what not to explain.
On the whole, I felt like things were constructed so that everything that was there was purposeful. Bits of code that were "odd" to an experienced programmer actually led to illustrating things. There were places where looping though something backwards was not really the nice way to design things, but it illustrated features of range() that needed to be illustrated. On the whole, I am really impressed with the choices. And while it is easy for me to think "well it could have taught X", there is just so much one can usefully put into a text.
Been doing a few youtube tutorials and online lectures so far, but have been itching to jump into it. I have a tendency to run with things before I can even crawl (let alone walk) so was wondering if these books I should set aside for a later date?
It does say they are for beginners but just thought i'd ask if anyone has any experience with em and if they are good or a waste of time?
Password cracking is not an easy job. Think about the search space you have to go through as the length of the password grows. Your list of the possible characters contains 26 letters and 10 digits (by the way you can use string.digits and string.ascii_lowercase). So, for the first character in your password there are 36 options. The second has 36 options, the 3rd has 36 options and so on. Therefor, for a password of length n you will have 3^n options. As you can quickly see, this number is growing extremely rapidly even for small numbers.
Your method of cracking the password is called Brute-force attack and it's extremely inefficient, especially considering the fact that most password are not stored as plain text but as hashed string.
Few other notes:
- You variables names are not great. Most of them are meaningless and it makes your code much harder to understand.
- You select random string instead of going through all the possible options in order. You have no way to cover all the options using this method. You can use itertools.permutations for iterating over all the options.
- Don't use parenthesis in
ifstatements, it's not the Python way. Please.
How about this:
import pyautogui
import time
import random
chars = "abcdefghijklmnopqrstuvwxyz"
chars_list = list(chars)
password = pyautogui.password("Enter a Password : ")
guess_password = ""
while(guess_password != password):
guess_password = random.choices(chars_list, k=len(password))
print("DECRYPTING"+ str(guess_password)+ "PASSWORD")
if(guess_password == list(password)):
print("Your password is : "+ "".join(guess_password))
break