0

I have small program written for me in Python to help me generate all combinations of passwords from a different sets of numbers and words i know for me to recover a password i forgot, as i know all different words and sets of numbers i used i just wanted to generate all possible combinations, the only problem is that the list seems to go on for hours and hours so eventually i run out of memory and it doesn't finish.

I got told it needs to dump my memory so it can carry on but i'm not sure if this is right. is there any way i can get round this problem?

this is the program i am running:

#!/usr/bin/python
import itertools
gfname = "name"
tendig = "1234567890"
sixteendig = "1111111111111111"
housenum = "99"
Characterset1 = "&&&&"
Characterset2 = "££££"
daughternam = "dname"
daughtyear = "1900"
phonenum1 = "055522233"
phonenum2 = "3333333"





mylist = [gfname, tendig, sixteendig, housenum, Characterset1,
          Characterset2, daughternam, daughtyear, phonenum1, phonenum2]
for length in range(1, len(mylist)+1):
    for item in itertools.permutations(mylist, length):
            print "".join(item)

i have taken out a few sets and changed the numbers and word for obvious reasons but this is roughly the program.

another thing is i may be missing a particular word but didnt want to put it in the list because i know it might go before all the generated passwords, does anyone know how to add a prefix to my program.

sorry for the bad grammar and thanks for any help given.

6
  • This program does not run out of memory, unless you have extremely little memory on your machine. It is quite efficient in fact. Commented Feb 3, 2013 at 12:51
  • i have 8 gigs of memory but do bear in mind i have took out a few sets of words and numbers Commented Feb 3, 2013 at 12:53
  • The code shown here will either run out of memory at or before the longest possible combination is shown, or not at all. The longest possible combination takes (on my 64-bit machine) 110 bytes of memory. The whole program will take, at most, kilobytes of memory, not gigabytes. Commented Feb 3, 2013 at 12:55
  • It'll take a very long time to go through all the possible permutations, sure. You want to find a point where you can stop and at another time continue perhaps, but you don't need a memory dump for that. You need to understand what the program does and find ways to partition that instead. Commented Feb 3, 2013 at 12:59
  • oh right i see, I'm not familiar with programming you see. I don't understand why i run out of memory, i left it to generate my passwords for several hours but stopped it before it had finished, so i copied and pasted the list into notepad and that created a 49 megabyte file. if i left it over night, which i have done it froze my pc and had messages saying i was low on memory. Commented Feb 3, 2013 at 13:05

4 Answers 4

1

I used guppy to understand the memory usage, I changed the OP code slightly (marked #!!!)

import itertools
gfname = "name"
tendig = "1234567890"
sixteendig = "1111111111111111"
housenum = "99"
Characterset1 = "&&&&"
Characterset2 = u"££££"
daughternam = "dname"
daughtyear = "1900"
phonenum1 = "055522233"
phonenum2 = "3333333"

from guppy import hpy # !!!
h=hpy()               # !!!
mylist = [gfname, tendig, sixteendig, housenum, Characterset1,
          Characterset2, daughternam, daughtyear, phonenum1, phonenum2]
for length in range(1, len(mylist)+1):
    print h.heap() #!!!
    for item in itertools.permutations(mylist, length):
            print item # !!!

Guppy outputs something like this every time h.heap() is called.

Partition of a set of 25914 objects. Total size = 3370200 bytes.
 Index  Count   %     Size   % Cumulative  % Kind (class / dict of class)
     0  11748  45   985544  29    985544  29 str
     1   5858  23   472376  14   1457920  43 tuple
     2    323   1   253640   8   1711560  51 dict (no owner)
     3     67   0   213064   6   1924624  57 dict of module
     4    199   1   210856   6   2135480  63 dict of type
     5   1630   6   208640   6   2344120  70 types.CodeType
     6   1593   6   191160   6   2535280  75 function
     7    199   1   177008   5   2712288  80 type
     8    124   0   135328   4   2847616  84 dict of class
     9   1045   4    83600   2   2931216  87 __builtin__.wrapper_descriptor

Running python code.py > code.log and the fgrep Partition code.log shows.

Partition of a set of 25914 objects. Total size = 3370200 bytes.
Partition of a set of 25924 objects. Total size = 3355832 bytes.
Partition of a set of 25924 objects. Total size = 3355728 bytes.
Partition of a set of 25924 objects. Total size = 3372568 bytes.
Partition of a set of 25924 objects. Total size = 3372736 bytes.
Partition of a set of 25924 objects. Total size = 3355752 bytes.
Partition of a set of 25924 objects. Total size = 3372592 bytes.
Partition of a set of 25924 objects. Total size = 3372760 bytes.
Partition of a set of 25924 objects. Total size = 3355776 bytes.
Partition of a set of 25924 objects. Total size = 3372616 bytes.

Which I believe shows that the memory footprint stays fairly consistent.

Granted I may be misinterpreting the results from guppy. Although during my tests I deliberately added a new string to a list to see if the object count increased and it did.

For those interested I had to install guppy like so on OSX - Mountain Lion pip install https://guppy-pe.svn.sourceforge.net/svnroot/guppy-pe/trunk/guppy

In summary I don't think that it's a running out of memory issue although granted we're not using the full OP dataset.

Sign up to request clarification or add additional context in comments.

8 Comments

this is all way past my head, sorry i don't understand what you have done, i know nothing about programming you see :(
I was just trying to illustrate that your code wouldn't appear to be running out of memory as I was dumping the memory used each time it went off to do another itertools.permutations(...) and the memory footprint didn't seem to move much. As suggested doing python yourcode.py > youlog.txt from a CMD window should run the code without issues. Try that and report back if you do have issues.
i have ran my code through again during the evening and i kept checking on it and it was ok, but then an hour later it had done the same again, which was out of memory. Im going to try something else by disabling a few things and leave it over night and ill let you know. Thanks for your help :)
I must say that on your sample above it ran in a couple of minutes - perhaps you should provide your full code and just sanitise the sensitive data but leave the relative lengths and number of fields.
Hi, I ran the code again over night but first disabled a few things, this time it didn't run out of memory but was still going when I woke up this morning. Am I wrong in thinking that there are 10 billion different combinations of my password? And is that why it's taking so long?
|
0

How about using IronPython and Visual Studio for its debug tools (which are pretty good)? You should be able to pause execution and look at the memory (essentially a memory dump).

3 Comments

thanks for your suggestion i will look into that but i do think i need to learn a little about programming.
plenty of python tutorials around, python is all the rage nowadays :)
it's a lot to take in when i am a complete beginner though, especially understanding my program. would there be a way for my program to paste results in notepad? sorry if its a silly question.
0

Your program will run pretty efficiently by itself, as you now know. But make sure you don't just run it in IDLE, for example; that will slow it down to a crawl as IDLE updates the screen with more and more lines. Save the output directly into a file.

Even better: Have you thought about what you'll do when you have the passwords? If you can log on to the lost account from the command line, try doing that immediately instead of storing all the passwords for later use:

for length in range(1, len(mylist)+1):
    for item in itertools.permutations(mylist, length):
        password = "".join(item)
        try_to_logon(command, password)

1 Comment

wow! I'm overwhelmed by all this info, its just all going well over my head. I'm so sorry for not understanding, I will be checking the passwords in a program, which then checks them against a winrar file but i do have a cryptainer file i have also to check, although I don't have any program to check that file because its not that popular. so with that one i may have to give up because there will be too many passwords to check through.
0

To answer the above comment from @shaun if you want the file to output to notepad just run your file like so

Myfile.py >output.txt

If the text file doesn't exist it will be created.

EDIT:

Replace the line in your code at the bottom which reads:

print "" .join(item)

with this:

with open ("output.txt","a") as f:
    f.write('\n'.join(items))
f.close

which will produce a file called output.txt. Should work (haven't tested)

7 Comments

sorry I'm confused about where to put that line
No problem. You don't add it to the actual code you add the >output.txt when you run the file from the command line. By doing this you are telling windows to push the output to a text file (notepad) rather than the screen. The other way to do this would be to alter your code to replace the line print "" .join(item) with code to open a text file and write to that instead. There are plenty of examples on stack overflow or google. I'm writing this on my mobile so it would be difficult for me to write the code.
oh right i see, thanks for explaining that to me, I'm sure I will be able to do that after a bit of research :)
No problem Shaun. When I get into the office tomorrow ill amend your code to output to a file without the need for > output.txt
Thank you very much Paul, I will give that a try when I get back from work.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.