primitive password cracker

2021-01-07 Thread Bischoop


I was practising for educational purpose with simply password cracker.
I know that I could use itertool but in my case when I'm learning I
would miss facing problems and learning on them and indeed I've met one
which is not giving me a peace.

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 '' later on'abaa' etc.

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']
mineset= set()
for a in letters:
for b in letters:
for c in letters:
for d in letters:
s = a + b + c + b
mylist.append(s)
mineset=set(mylist)

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.
And finally, I was struglling with making it in without creating four
loops for four letters, something like that:

To try to solve those I went with that approach:

-
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']
password = 'pass'
combin = ''
lista=[]

for x in range(4):
for y in letters:
combin +=y
lista.append(combin)
combin=''
mineset=set(lista)
print(mineset)
for i in lista:
if i == password:
print('pass:', i)
---
But the results are disspainting:
{'abc', 'a', 'ab', 'abcd', 'abcde'}

I was seating on it for a long day but can't even closely achieve
similar effect to 4 loops in previous code.

--
Thanks
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Tkinter menu item underline syntax [RESOLVED]

2021-01-07 Thread Peter Otten

On 06/01/2021 22:03, Rich Shepard wrote:

On Thu, 7 Jan 2021, Chris Angelico wrote:


Are you sure that this works? It's syntactically valid, but I don't
think it means what you think it does.


ChrisA,

I'm always open to learning. There's no error generated ... yet the
application doesn' open so it's time to run it through pdb.


Spoiler: unless the name 'underline' is defined you get a NameError:

NameError: name 'underline' is not defined

If it is defined and self.callbacks is a dict you get a TypeError:

TypeError: unhashable type: 'slice'

because that's what a colon means in a context like

x[a:b]

From what you posted I would guess that underline is most likely a 
keyword argument to the add_command() method:


file_menu.add_command(
label='New',
command=self.callbacks['file->new'],
underline=0,
accelerator='Ctrl+N'
)

--
https://mail.python.org/mailman/listinfo/python-list


Re: Tkinter menu item underline syntax [RESOLVED]

2021-01-07 Thread Peter Otten

On 06/01/2021 22:03, Grant Edwards wrote:


I'm completely baffled by that. Can somebody explain how this
expression is evaluated?

self.callbacks['file->new', underline: 0]

It appears that the dict callbacks is being accessed with the key of
a tuple comprising a string and a slice.

Huh?


You're completely right:

>>> class C:
def __getitem__(self, index): return index


>>> c = C()
>>> underline = 42
>>> c["foo", underline: 0]
('foo', slice(42, 0, None))

The OP's code will most certainly fail at runtime ;)



--
https://mail.python.org/mailman/listinfo/python-list


Re: primitive password cracker

2021-01-07 Thread Chris Angelico
On Thu, Jan 7, 2021 at 8:46 PM Bischoop  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 '' 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
-- 
https://mail.python.org/mailman/listinfo/python-list


EuroPython 2021: Format Poll

2021-01-07 Thread M.-A. Lemburg
We are currently working out the format for this year’s online
EuroPython conference. The conference will be run using online
conference tools during the week of July 26 - August 1 and we would like
to learn about your preferences regarding the overall structure.

For this reason, we’re running a poll to gather input from our
(potential) attendees:

* EuroPython 2021 Format Poll *

  https://forms.gle/V4oPEXWiexfVyH1S7


Please add any comments you may have to the comment field. We’d love to
hear about new online conference platforms you may have seen (last year,
we used Zoom and Discord), suggestions on social event formats, etc.


Help spread the word


Please help us spread this message by sharing it on your social
networks as widely as possible. Thank you !

Link to the blog post:

https://blog.europython.eu/post/639651925251571712/europython-2021-format-poll

Tweet:

https://twitter.com/europython/status/1347146647403450370

Thanks,
--
EuroPython 2021 Team
https://www.europython-society.org/

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Tkinter menu item underline syntax [RESOLVED]

2021-01-07 Thread Rich Shepard

On Thu, 7 Jan 2021, Peter Otten wrote:


Spoiler: unless the name 'underline' is defined you get a NameError:
NameError: name 'underline' is not defined
If it is defined and self.callbacks is a dict you get a TypeError:
TypeError: unhashable type: 'slice'
because that's what a colon means in a context like
x[a:b]


The template I used for the menu doesn't scale to my application so I'm
re-writing it from scratch.

Thanks, all,

Rich
--
https://mail.python.org/mailman/listinfo/python-list


Re: primitive password cracker

2021-01-07 Thread Bischoop
On 2021-01-07, Chris Angelico  wrote:
>
> 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.
>

Yes that's definitely better, I've done so.
>> 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.
>

ha, that's typo I was working so long on it that got mixed up.
and yes with 'd' it works :-)

>> 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.
>
The problem was with that 'b' at the end, now it solved.


>> 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.
>
Well :-) I tried to do shorter version of the previous code to do not do
for loop for every character, range
supposed to be for how long the password is, in this case four
characters, once the 4character combination is made add it to the list,
similarly to the previous code but my logic is wrong here.
I don't have clue hot to tell: get a letter for 1 get for 2 get for 3
and get for 4.




> 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!
>

For me is even not debbuging code is important but to do
what I want and in that case is that what I mention earlier four
letters picked and add them to the list, and today again I seat on it
and just nothing lol.

--
Thanks
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Tkinter menu item underline syntax [RESOLVED]

2021-01-07 Thread Terry Reedy

On 1/6/2021 4:17 PM, Terry Reedy wrote:

On 1/6/2021 4:03 PM, Rich Shepard wrote:

On Thu, 7 Jan 2021, Chris Angelico wrote:


Are you sure that this works? It's syntactically valid, but I don't
think it means what you think it does.


ChrisA,

I'm always open to learning. There's no error generated ... yet the
application doesn' open so it's time to run it through pdb.


See my response, sent an hour ago, for how to use 'underline.


Reposting:

'underline' has nothing to do with looking up the command in 
self.callbacks.  It is a keyword parameter for the add_command method, 
and is handled like all other values passed by name, and as you did for 
the other arguments


  file_menu.add_command(
  label='New',
  underline=0,
  command=self.callbacks['file->new],
  accelerator='Ctrl+N'
  )

Note: PEP 8 style is no spaces around '=' used for keyword  arguments. 
Here is an example from idlelib.editor, 978.


menu.add_command(label=ulchars[i] + " " + file_name,
 command=callback,
 underline=0)




--
Terry Jan Reedy

--
https://mail.python.org/mailman/listinfo/python-list


Some problem in code execution in python

2021-01-07 Thread Dario Dario
Sir, I am one of the user of your python program, that is after completion
of installation I got some statement like "you got code execution problem
". I don't know how to rectify this problem.so please help me to rectify
this problem .
You send me the solution in this email ID itself .
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Class and tkinter problem

2021-01-07 Thread Terry Reedy

On 1/7/2021 2:42 AM, Christian Gollwitzer wrote:

Am 07.01.21 um 08:29 schrieb Paulo da Silva:


Does anybody know why cmd method isn't called when I change the button
state (clicking on it) in this example?
I know that this seems a weird class use. But why doesn't it work?
Thanks.

class C:
 from tkinter import Checkbutton
 import tkinter

 @staticmethod

^^it works if you remove the staticmethod here


staticmethods are essentially useless in Python.  What little was gained 
by their addition is partly offset by the introduced confusion.


I am not sure is removing @staticmethod would have been sufficient in 2.x.


 def cmd():
 print("Test")



top=tkinter.Tk()
cb=Checkbutton(command=cmd)
cb.pack()

Button commands have to be tcl functions.  Tkinter wraps Python 
functions as tcl function.  Static methods also wrap python functions, 
as a .__func__ attribute.  So the code if one passes cmd.__func__.



Maybe there is a bug in tkinter, that it doesn't work with static methods?


One could propose that tkinter test whether callables are staticmethods 
and unwrap them when they are.


Classmethods also do not work as is.  By experiment, the following works.
cb=Checkbutton(command=lambda: C.cmd.__func__(C))
But if the class were nested, it would be more complicated.

--
Terry Jan Reedy


--
https://mail.python.org/mailman/listinfo/python-list


Re: primitive password cracker

2021-01-07 Thread Bischoop
On 2021-01-07, Chris Angelico  wrote:

This could allow easy to change the number of  characters in
combination, just pass n argument to range where n is how many characters.


-- 
https://mail.python.org/mailman/listinfo/python-list


RE: primitive password cracker

2021-01-07 Thread David Raymond
I think you might want to check out itertools.product()
https://docs.python.org/3.9/library/itertools.html#itertools.product

import itertools
import string
passe = 'pass'
for p in itertools.product(string.ascii_lowercase, repeat = 4):
p = "".join(p)
if p == passe:
print("Found it:", p)
break
else:
print("Didn't find it.")

Or for different lengths:

foundIt = False
for repeat in range(1, 6):
for p in itertools.product(string.ascii_lowercase, repeat = repeat):
p = "".join(p)
if p == passe:
print("Found it:", p)
foundIt = True
break
if foundIt:
break
else:
print("Didn't find it.")
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: primitive password cracker

2021-01-07 Thread Chris Angelico
On Fri, Jan 8, 2021 at 2:12 AM Bischoop  wrote:
>
> On 2021-01-07, Chris Angelico  wrote:
>
> This could allow easy to change the number of  characters in
> combination, just pass n argument to range where n is how many characters.
>

True. Unfortunately, it doesn't work, so what you'd have is something
that can be easily parameterized to not work on other numbers of
characters too. :)

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Tkinter menu item underline syntax [RESOLVED]

2021-01-07 Thread Rich Shepard

On Wed, 6 Jan 2021, Terry Reedy wrote:


'underline' has nothing to do with looking up the command in
self.callbacks. It is a keyword parameter for the add_command method, and
is handled like all other values passed by name, and as you did for the
other arguments

 file_menu.add_command(
 label='New',
 underline=0,
 command=self.callbacks['file->new],
 accelerator='Ctrl+N'
 )

Note: PEP 8 style is no spaces around '=' used for keyword  arguments. Here 
is an example from idlelib.editor, 978.


   menu.add_command(label=ulchars[i] + " " + file_name,
command=callback,
underline=0)


Thank you for the clarification.

Rich
--
https://mail.python.org/mailman/listinfo/python-list


Re: Class and tkinter problem

2021-01-07 Thread Peter Otten

On 07/01/2021 08:42, Christian Gollwitzer wrote:

Am 07.01.21 um 08:29 schrieb Paulo da Silva:


Does anybody know why cmd method isn't called when I change the button
state (clicking on it) in this example?
I know that this seems a weird class use. But why doesn't it work?
Thanks.

class C:
 from tkinter import Checkbutton
 import tkinter

 @staticmethod

^^it works if you remove the staticmethod here


 def cmd():
 print("Test")



Maybe there is a bug in tkinter, that it doesn't work with static methods?


It has nothing to do with tkinter, a staticmethod object cannot be
called directly:

>>> class C:
@staticmethod
def cmd(): print("Hello")
cmd()


Traceback (most recent call last):
  File "", line 1, in 
class C:
  File "", line 4, in C
cmd()
TypeError: 'staticmethod' object is not callable

You have to go through the descriptor protocol:

>>> class C:
@staticmethod
def cmd(): print("Hello")


>>> C.cmd()
Hello

I recommend that the OP use a more conventional stye and do the setup
outside the class or, better, in an instance of the class.

--
https://mail.python.org/mailman/listinfo/python-list


Re: Some problem in code execution in python

2021-01-07 Thread David L Neil via Python-list
On 07/01/2021 22.44, Dario Dario wrote:
> Sir, I am one of the user of your python program, that is after completion
> of installation I got some statement like "you got code execution problem
> ". I don't know how to rectify this problem.so please help me to rectify
> this problem .
> You send me the solution in this email ID itself .


Welcome to the list, where Python users help each other.

Please send more information:
- which Operating System
- which version of Python
- from where Python was downloaded
- copy-paste all of the error messages
-- 
Regards =dn
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Some problem in code execution in python

2021-01-07 Thread Bischoop
On 2021-01-07, Dario Dario  wrote:
> Sir, I am one of the user of your python program, that is after completion
> of installation I got some statement like "you got code execution problem
> ". I don't know how to rectify this problem.so please help me to rectify
> this problem .
> You send me the solution in this email ID itself .

I'm not Window OS user but doesn't running program in Windows Command Shell
tells also what's wrong?


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Class and tkinter problem

2021-01-07 Thread Paulo da Silva
Às 07:42 de 07/01/21, Christian Gollwitzer escreveu:
> Am 07.01.21 um 08:29 schrieb Paulo da Silva:
> 
>> Does anybody know why cmd method isn't called when I change the button
>> state (clicking on it) in this example?
>> I know that this seems a weird class use. But why doesn't it work?
>> Thanks.
>>
>> class C:
>>  from tkinter import Checkbutton
>>  import tkinter
>>
>>  @staticmethod
> ^^it works if you remove the staticmethod here

Yes, that's the coventional way.
Thanks

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Class and tkinter problem

2021-01-07 Thread Paulo da Silva
Às 09:20 de 07/01/21, Terry Reedy escreveu:
> On 1/7/2021 2:42 AM, Christian Gollwitzer wrote:
>> Am 07.01.21 um 08:29 schrieb Paulo da Silva:
>>
>>> Does anybody know why cmd method isn't called when I change the button
>>> state (clicking on it) in this example?
>>> I know that this seems a weird class use. But why doesn't it work?
>>> Thanks.
>>>
>>> class C:
>>>  from tkinter import Checkbutton
>>>  import tkinter
>>>
>>>  @staticmethod
>> ^^it works if you remove the staticmethod here
> 
> staticmethods are essentially useless in Python.  What little was gained
> by their addition is partly offset by the introduced confusion.
It depends on what the classes are being used for.
Sometimes I just want to use them as static wrappers.
Of course I could use them in the conventional way for this purpose, but
it's not so clean :-)
...

> 
> Classmethods also do not work as is.  By experiment, the following works.
>     cb=Checkbutton(command=lambda: C.cmd.__func__(C))
Why not just
cb=Checkbutton(command=lambda : C.cmd()) ?
Also works.
BTW, just for curiosity, and for my personal learning ... What does
"__func__" does?

Thank you.


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Class and tkinter problem

2021-01-07 Thread Paulo da Silva
Às 16:02 de 07/01/21, Peter Otten escreveu:
> On 07/01/2021 08:42, Christian Gollwitzer wrote:
>> Am 07.01.21 um 08:29 schrieb Paulo da Silva:
>>
...

> 
> I recommend that the OP use a more conventional stye and do the setup
> outside the class or, better, in an instance of the class.
> 
There are lots of possible more conventional ways, of course.
My purpose was only to understand what was wrong.

Thanks anyway.


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: primitive password cracker

2021-01-07 Thread Bischoop
On 2021-01-07, Chris Angelico  wrote:
>
> True. Unfortunately, it doesn't work, so what you'd have is something
> that can be easily parameterized to not work on other numbers of
> characters too. :)
>

My bad is I'm kinda maniac and have to know how to, I know best solution
itertool but... I just must know, was thinking that studing the itertool
code would give me an answer but found it's in C.
Now I try list comprehension for it, so it's another day on it for me.


--
Thanks
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: primitive password cracker

2021-01-07 Thread Bischoop
On 2021-01-07, David Raymond  wrote:
> I think you might want to check out itertools.product()
> https://docs.python.org/3.9/library/itertools.html#itertools.product


Thanks David for contribution I find it very convenient but not knowing
how to solve solution without itertools for:
for a i :
for b in :
for c in :
for d in :


doesn't give me a peace.

--
Thanks



-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Class and tkinter problem

2021-01-07 Thread Paulo da Silva
Às 07:29 de 07/01/21, Paulo da Silva escreveu:
> Hi!
> 
> Does anybody know why cmd method isn't called when I change the button
> state (clicking on it) in this example?
> I know that this seems a weird class use. But why doesn't it work?
> Thanks.
> 
> class C:
> from tkinter import Checkbutton
> import tkinter
> 
> @staticmethod
> def cmd():
> print("Test")
> 
> top=tkinter.Tk()
> cb=Checkbutton(command=cmd)
> cb.pack()
> 
> @staticmethod
> def loop():
> C.top.mainloop()
> 
> c=C()
> c.loop()
> 

After some experiments I found two solutions:

1)

class C:
@staticmethod
def cmd():
print("Test")
class C: #@DuplicatedSignature
from tkinter import Checkbutton
import tkinter

top=tkinter.Tk()
cb=Checkbutton(command=C.cmd)
cb.pack()

@staticmethod
def loop():
C.top.mainloop()

c=C()
c.loop()

2)

class C:
from tkinter import Checkbutton
import tkinter

@staticmethod
def cmd():
print("Test")

top=tkinter.Tk()
cb=Checkbutton(command=lambda : C.cmd())
cb.pack()

@staticmethod
def loop():
C.top.mainloop()

c=C()
c.loop()

This one as a sequence of the answer of Terry - thanks.

BTW, does anyone know I can I get the arguments eventually passed by the
Checkbutton event, or any other widget callback (*pargs, **kargs) using
this "solution"?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: primitive password cracker

2021-01-07 Thread Bischoop
On 2021-01-07, Bischoop  wrote:
> On 2021-01-07, Chris Angelico  wrote:
>>
>> True. Unfortunately, it doesn't work, so what you'd have is something
>> that can be easily parameterized to not work on other numbers of
>> characters too. :)
>>
>
> My bad is I'm kinda maniac and have to know how to, I know best solution
> itertool but... I just must know, was thinking that studing the itertool
> code would give me an answer but found it's in C.
> Now I try list comprehension for it, so it's another day on it for me.
>
>

So after checking itertools doc I found what itertools.product is
quivalent for on: 
https://docs.python.org/3/library/itertools.html#itertools.product

Now I'll sleep.

--
Thanks
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: primitive password cracker

2021-01-07 Thread David Kolovratník
I find a parallel to counting useful. Let letters be '0' to '9'
and think of manual (in contrast to formatting range(0, 10))
construction of list of strings "" to "" 

Let's start with . How do you compute the next item? Start
looking from its end. I stop here in order to leave space for 
Bischoop's deliberation.

To sum up in order words, the clue is to stop thinking of inner
loops for each letter and find a way to get the next combination.

Best,
David

On Thu, Jan 07, 2021 at 04:52:56PM -, Bischoop wrote:
> On 2021-01-07, Chris Angelico  wrote:
> >
> > True. Unfortunately, it doesn't work, so what you'd have is something
> > that can be easily parameterized to not work on other numbers of
> > characters too. :)
> >
> 
> My bad is I'm kinda maniac and have to know how to, I know best solution
> itertool but... I just must know, was thinking that studing the itertool
> code would give me an answer but found it's in C.
> Now I try list comprehension for it, so it's another day on it for me.
> 
> 
> --
> Thanks
> -- 
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: primitive password cracker

2021-01-07 Thread dn via Python-list
On 08/01/2021 05.52, Bischoop wrote:
> On 2021-01-07, Chris Angelico  wrote:
>>
>> True. Unfortunately, it doesn't work, so what you'd have is something
>> that can be easily parameterized to not work on other numbers of
>> characters too. :)
>>
> 
> My bad is I'm kinda maniac and have to know how to, I know best solution
> itertool but... I just must know, was thinking that studing the itertool
> code would give me an answer but found it's in C.
> Now I try list comprehension for it, so it's another day on it for me.


BTW have you realised a second 'typo' - that there are only 24 letters
in this 'alphabet'?


It is not difficult to parametrise the building of a "password cracking
dictionary"! (NB not same definition as a Python dictionary) Take it one
step (one character) at a time...

We start from our list of "letters". This is every permutation of the
alphabet, taken one at a time. Call it the one_character_list.
[Let's not distract from the problem by arguing about the definition of
"permutation"!]

Next, we'll take the one_character_list and permute that, with each of
our letter[s]. Thus 'a, b, c' expands to 'aa, ab, ac, ... ba, bb, bc,
... ca, cb, cc, ...'.

For every one of the 24 elements of the one_character_list we now have
24 elements in the two_character_list, ie len( two_character_list )
should be 24*24 (== 24**2) and each element should be unique (ie same
rule as a set).
NB above equation varies if the rule for what may be the first character
of a password differs for the rule of which letters/characters may follow!

Similarly, if we take the two_character_list, we can permute that
(again/further) with each letter. Thus 'aaa, aab, aac, ...baa, bab, bac,
...'. Thus, len( three_character_list ) == 24 * 24 * 24 == 24 ** 3 ==
len( two_character_list ) * 24 == len( one_character_list ) * 24 * 24

Carrying-on we can build a "password cracking dictionary" of any length.
NB the three-character_list contains exactly 'what it says on the tin'
(English-English expression meaning that the label is entirely correct).
Thus if the password rules say 'up to three characters in length', then
the password-cracker would have to test each of the three lists in-turn
too look for one-character passwords, then two-character passwords, and
finally three...!


Disclaimers:

Permutations and combinations are an interesting [learning] exercise,
and we're getting used to your preference for step-by-step
experimentation and learning-mastery.

That said, @David is correct - once understood, use the tool! Because
these multiple loops are "expensive" (in terms of execution-time).

Per @Chris and comments above, consider when and where to use
character-strings, tuples, lists, and/or sets - for 'best results'
and/or 'best practice'.

Per @yourself, once you have coded, tested, and debugged a solution
featuring explicit for-loops, it will be a valuable exercise to upgrade
(the code and quite probably the execution speed) using
comprehensions/expressions...



Sample code:

def permute_lists( existing_list:list, expansion_list:list )->list:
'''Expand each of the existing list's elements
with every element of a provided list.
'''
permuted_list = list()
for existing_element in existing_list:
for expansion_element in expansion_list:
permuted_list.append( existing_element + expansion_element )
return permuted_list


# establish character-set to be used
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']

# taking each of the letters once is the character-set
one_character_list = letters
print( len( one_character_list ) )
print( one_character_list, end="\n" )

# taking the letters two at a time
two_character_list = permute_lists( one_character_list, letters )
print( len( two_character_list ), len( one_character_list ) * len(
letters ) )
print( two_character_list, end="\n" )

# taking the letters three at a time
three_character_list = permute_lists( two_character_list, letters )
print( len( three_character_list ), len( two_character_list ) * len(
letters ) )
print( three_character_list, end="\n" )

-- 
Regards =dn
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Class and tkinter problem

2021-01-07 Thread Terry Reedy

On 1/7/2021 4:20 AM, Terry Reedy wrote:

On 1/7/2021 2:42 AM, Christian Gollwitzer wrote:

Am 07.01.21 um 08:29 schrieb Paulo da Silva:


Does anybody know why cmd method isn't called when I change the button
state (clicking on it) in this example?
I know that this seems a weird class use. But why doesn't it work?
Thanks.

class C:
 from tkinter import Checkbutton
 import tkinter

 @staticmethod

^^it works if you remove the staticmethod here


staticmethods are essentially useless in Python.  What little was gained 
by their addition is partly offset by the introduced confusion.



 def cmd():
 print("Test")


The confusion is that methods are callable, whereas 'staticmethods' are 
not.  I was not completely aware of this until pointed out by Peter 
Otten with example


"cmd()

Traceback (most recent call last):
  File "", line 1, in 
class C:
  File "", line 4, in C
cmd()
TypeError: 'staticmethod' object is not callable

You have to go through the descriptor protocol:"

Indeed, dir(cmd) shows that it does not have a .__call__ attribute.


     top=tkinter.Tk()
     cb=Checkbutton(command=cmd)


Button commands have to be tcl functions.  Tkinter wraps Python 
functions as tcl function.  Static methods also wrap python functions, 
as a .__func__ attribute.  So the code if one passes cmd.__func__.


"So the code works if one passes the callable cmd.__func__."

Maybe there is a bug in tkinter, that it doesn't work with static 
methods?


One could propose that tkinter test whether callables are staticmethods 


Command options, as documented, must be callables. Neither staticmethods 
nor classmethods are callable.



and unwrap them when they are.


 I would propose instead that if possible tkinter raise TypeError when 
passed a non-callable as a command.



Classmethods also do not work as is.  By experiment, the following works.
     cb=Checkbutton(command=lambda: C.cmd.__func__(C))
But if the class were nested, it would be more complicated.



--
Terry Jan Reedy


--
https://mail.python.org/mailman/listinfo/python-list


This is a test

2021-01-07 Thread Craig Hatch
I have added you to the EMAIL  list, so when I have questions.

Just learn for fun.


Craig Hatch
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: primitive password cracker

2021-01-07 Thread Greg Ewing

Another way to approach this problem is using recursion, e.g.

def find_combinations(items, n, comb, result):
  if n == 0:
result.append(comb)
  else:
for item in items:
  find_combinations(items, n - 1, comb + [item], result)

words = []
find_combinations(['a', 'b', 'c'], 3, [], words)
print(words)

For this particular problem it's less efficient than the
technique used by itertools.product, because it generates
sub-combinations multiple times. However, it's a useful
technique to keep in mind whenever you have a "variable
number of nested for-loops" kind of problem.

--
Greg

--
https://mail.python.org/mailman/listinfo/python-list


Re: primitive password cracker

2021-01-07 Thread Chris Angelico
On Fri, Jan 8, 2021 at 11:31 AM Greg Ewing  wrote:
>
> Another way to approach this problem is using recursion, e.g.
>
> def find_combinations(items, n, comb, result):
>if n == 0:
>  result.append(comb)
>else:
>  for item in items:
>find_combinations(items, n - 1, comb + [item], result)
>
> words = []
> find_combinations(['a', 'b', 'c'], 3, [], words)
> print(words)
>

True, but I'd much rather write it as a generator:

def permute(items, n):
if not n:
yield ""
return
# Optional performance enhancement:
if n == 1: return (yield from items)
for item in items:
for rest in permute(items, n - 1):
yield item + rest

words = list(permute("abc", 3))

I'm not sure how performance would go, but this is a lot cleaner.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Class and tkinter problem

2021-01-07 Thread Paulo da Silva
Às 20:35 de 07/01/21, Terry Reedy escreveu:
> On 1/7/2021 4:20 AM, Terry Reedy wrote:
>> On 1/7/2021 2:42 AM, Christian Gollwitzer wrote:
>>> Am 07.01.21 um 08:29 schrieb Paulo da Silva:
>>>
 Does anybody know why cmd method isn't called when I change the button
 state (clicking on it) in this example?
 I know that this seems a weird class use. But why doesn't it work?
 Thanks.

 class C:
  from tkinter import Checkbutton
  import tkinter

  @staticmethod
>>> ^^it works if you remove the staticmethod here
>>
>> staticmethods are essentially useless in Python.  What little was
>> gained by their addition is partly offset by the introduced confusion.
> 
  def cmd():
  print("Test")
> 
> The confusion is that methods are callable, whereas 'staticmethods' are
> not.  I was not completely aware of this until pointed out by Peter
> Otten with example
> 
> "    cmd()
> 
> Traceback (most recent call last):
>   File "", line 1, in 
>     class C:
>   File "", line 4, in C
>     cmd()
> TypeError: 'staticmethod' object is not callable
> 
> You have to go through the descriptor protocol:"
> 
> Indeed, dir(cmd) shows that it does not have a .__call__ attribute.
> 
>>  top=tkinter.Tk()
>>  cb=Checkbutton(command=cmd)
> 
>> Button commands have to be tcl functions.  Tkinter wraps Python
>> functions as tcl function.  Static methods also wrap python functions,
>> as a .__func__ attribute.  So the code if one passes cmd.__func__.
> 
> "So the code works if one passes the callable cmd.__func__."
> 
>>> Maybe there is a bug in tkinter, that it doesn't work with static
>>> methods?
>>
>> One could propose that tkinter test whether callables are staticmethods 
> 
> Command options, as documented, must be callables. Neither staticmethods
> nor classmethods are callable.
> 
>> and unwrap them when they are.
> 
>  I would propose instead that if possible tkinter raise TypeError when
> passed a non-callable as a command.
> 
Yes, that would be much better.
Thanks.
-- 
https://mail.python.org/mailman/listinfo/python-list