December 2023
Intermediate to advanced
504 pages
11h 43m
English
You’re a hacker (an ethical one, of course) who’s trying to figure out someone’s password. You decide on a brute-force approach and write some code that produces every possible string of a given length. Here’s the code you whipped up:
| | from string import ascii_lowercase |
| | import itertools |
| | |
| | |
| | def every_password(length): |
| | for s in itertools.product(ascii_lowercase, repeat=length): |
| | print("".join(s)) |
In our code, we’ve imported the entire alphabet using ascii_lowercase from Python’s string module so we don’t have to actually type out the entire alphabet. We’ve also used Python’s itertools module to allow us to run an arbitrary number of nested loops with minimum code.
In truth, we’re not going to focus ...
Read now
Unlock full access