[Pentesting][Math] Bruteforce passwords using cartesian product

Yet another use of Python's itertools.product, enumerate all passwords. In fact, this is cartesian product over character sets.

#!/usr/bin/env python3

import itertools

_0_9=list(map(lambda x: chr(ord('0')+x), range(10)))
_a_z=list(map(lambda x: chr(ord('a')+x), range(26)))
_specials=['_', '!', '-']

full_set=_0_9+_a_z+_specials

password_length=3

for x in itertools.product(full_set, repeat=password_length):
    print ("".join(x))

Can you do it using shorter code?

Also, all possible combinations of username and passwords is also a cartesian product of these sets.

(the post first published at 20251218.)


List of my other blog posts. Subscribe to my news feed,
If you enjoy my work, you can support it on patreon.
Some time ago (before 24-Mar-2025) there was Disqus JS script for comments. I dropped it --- it was so motley, distracting, animated, with too much ads. I never liked it. Also, comments din't appeared correctly (Disqus was buggy). Also, my blog is too chamberlike --- not many people write comments here. So I decided to switch to the model I once had at least in 2020 --- send me your comments by email (don't forget to include URL to this blog post) and I will copy&paste it here manually.
Let's party like it's ~1993-1996, in this ultimate, radical and uncompromisingly primitive pre-web1.0-style blog and website. This website is best viewed under lynx/links/elinks/w3m.
Or use my zulip for feedback.