-6

I want to make a list like this:

7785237_770x770_de3b540dc13ed50023d17854513b40aa07e50a6a
732308_770x770_ec5c344c0114011a5306b31142ff9b001813f6d6
7430796_800x800_ec0f2e614e2dc460fca7e626d83073c827dc9130
7431018_800x800_7caa40b85c21485c64f2ad509a0d9cc1ed3ba526

So to explain: First block before the first "_" is just a number between 0 and 9500000 - second block varies between two variables: "770x770" and "800x800"
Last block is a 40 character long HEX block.

So what I want to do, is to generate all possible combinations of these, and combine it into one line.

How do I do this? Don't know if it can be done in BASH, or it should be done in perl/something similar.

13
  • 5
    all possible combinations of these you mean all possible combinations of 16**40*9500000*2 so 27768531109287155445870011821609377373462718316544000000 lines?
    – neurino
    Commented May 12, 2012 at 23:30
  • 4
    You cannot generate a file containing 9500001*2*16^40 lines. That file would be something like a trillion (US) times the total size of all hard disks in the world. What are you trying to do? A 40-digit hex string looks like a SHA-1 hash; this kind of hash is designed so that you cannot find the right one unless you know what it's the hash of. If you're trying a brute-force search on an image server, forget it; you can't do it, by design. Commented May 12, 2012 at 23:46
  • 2
    The FAQ says: "You should only ask practical, answerable questions based on actual problems that you face."
    – Mikel
    Commented May 12, 2012 at 23:53
  • 3
    @FrederikNielsen If the ability to reasonably complete your task also implies the ability to brute-force 128-bit symmetric encryption and 160-bit hashes, then no I would not call it practical. If you are or ever become a pointy-haired boss, I'd hate to be one of your employees ... :P
    – jw013
    Commented May 13, 2012 at 0:01
  • 2
    @FrederikNielsen - Yeah, don't do that.
    – Chris Down
    Commented May 13, 2012 at 5:48

1 Answer 1

2

I guess bash cannot handle those amounts and in case it could you'd get old before it sorts it out.

Python itertools can help you creating and assembling all combinations.

I suggest Python and not perl as this is more a math task rather than a text manipulation one.

#!/usr/bin/env python

from itertools import combinations_with_replacement

for x in combinations_with_replacement('0123456789abcdef', 40):
    h = ''.join(x)
    for y in xrange(9500001):
        for r in ("770x770", "800x800"):
            print "{0}_{1}_{2}".format(y, r, h)

Of course Python is way slower than C so don't expect best performances. On the other side don't expect to get the same result in C with only 5 lines of code.

6
  • Looks good Neurino. Now I just gotta figure out how I get the itertools to work on my centos box..
    – Frederik
    Commented May 12, 2012 at 23:57
  • python is installed by default on most linux distributions, I think centOS does too. Anyway given it has no practical applications you may not want to save results to a file but simply create a function and let it yield instead of print results.
    – neurino
    Commented May 13, 2012 at 0:04
  • Yeah sounds about right, but centos comes with an old python as far as i can see. So trying to compile a newer one now. Anyhow, thanks for the piece of code :)
    – Frederik
    Commented May 13, 2012 at 0:10
  • I get a syntax error on line 9, at the last " - says Invalid Syntax.. Is it my box thats acting strange, or is there something else wrong?
    – Frederik
    Commented May 13, 2012 at 0:15
  • Works here with copy & paste.
    – jippie
    Commented May 13, 2012 at 7:57

Not the answer you're looking for? Browse other questions tagged .