primitive password cracker

Chris Angelico rosuav at gmail.com
Thu Jan 7 06:56:58 EST 2021


On Thu, Jan 7, 2021 at 8:46 PM Bischoop <Bischoop at vimart.net> wrote:
> What I want to learn is if I need get for example four combinations, so
> how to get in a loop first letter 'a',then another step'a' and again 'a'
> and 'a', to have 'aaaa' later on'abaa' etc.

So you want every possible four-letter combination?

> So I wrote that:
> ------------------------------------------
> import string
> passe = 'zulu'
> mylist = []
> #letters = string.ascii_lowercase
> letters = ['a','b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'r', 's', 't', 'u', 'w', 'q', 'y', 'z']

I'd recommend having just a string, rather than a list; it'll behave
identically for what you're doing, and it'll be a lot easier to see
when you have all the right letters.

I'd also recommend having the letters in some well-known order, such
as lexicographic (aka "alphabetical order"), or running straight
across the rows of your keyboard. Keyboards aren't all the same, but
at least you'll know that your own keyboard is consistent.

> mineset= set()
> for a in letters:
>     for b in letters:
>         for c in letters:
>             for d in letters:
>                 s = a + b + c + b

Why is b at the end? :) That's why "zulu" could be found, but "pass" couldn't.

> k = sorted(mineset)
> print(k)
> for i in k:
>     if i == passe:
>         print('got it: ', i )
> print(passe in k)
> --------------------------------------
> It works in someway but the problems are:
> Not all combination are made, I change password to: 'pass' and that combination is not in results.
> Another thing is, I had to made a set from list because combinations
> were repeated.

Yep. I'd recommend looking at the original list rather than setting
and sorting, and you might notice patterns that hint at problems.

> for x in range(4):
>     for y in letters:
>         combin +=y
>         lista.append(combin)
>     combin=''

Not entirely sure what your intended logic is here, but I'd advise
planning things out in pseudocode and knowing what you're actually
building.

Debugging code can be very hard, especially if you don't know what
it's doing. Fortunately, Python comes with a number of tools to help
you figure out your code; the simplest is the print function - just
add a few useful print calls to your code and trace through things
that way. You can also look at the pdb module, and various other
techniques. Explore your code, get to know how it works at each point,
and you should be able to figure things out.

Good luck, have fun! And remember IIDPIO: If In Doubt, Print It Out!

ChrisA


More information about the Python-list mailing list