• Welcome to Valhalla Legends Archive.
 

[C++] Gigantic Loops

Started by Joe[x86], October 16, 2005, 01:11 AM

Previous topic - Next topic

Joe[x86]

Basically, I'm trying to loop from 0 to 9999999999999. This is too long for a long, and clearly for an int. I fixed the problem, but its a really, really discusting way. I can't think of a better way to do it though. Anyone know how to make this code a bit better?

void genKeys() {
  int a, b, c, d, e, f, g, h, i, j, k, l, m;
  string key = "0000000000000";
  a = 0; b = 0; c = 0; e = 0; f = 0; g = 0; h = 0; i = 0; j = 0; k = 0; l = 0; m = 0;
  for(a = 0; a < 10; a++) {
    for(b = 0; b < 10; b++) {
      for(c = 0; c < 10; c++) {
        for(d = 0; e < 10; f++) {
          for(e = 0; e < 10; e++) {
            for(f = 0; f < 10; f++) {
              for(g = 0; g < 10; g++) {
                for(h = 0; h < 10; h++) {
                  for(i = 0; i < 10; i++) {
                    for(j = 0; j < 10; j++) {
                      for(k = 0; k < 10; k++) {
                        for(l = 0; l < 10; l++) {
                          for(m = 0; m < 10; m++) {
                            //cout << a << b << c << d << e << f << g << h << i << j << k << l << m << endl;
                            key[0]  = a + 0x30;
                            key[1]  = b + 0x30;
                            key[2]  = c + 0x30;
                            key[3]  = d + 0x30;
                            key[4]  = e + 0x30;
                            key[5]  = f + 0x30;
                            key[6]  = g + 0x30;
                            key[7]  = h + 0x30;
                            key[8]  = i + 0x30;
                            key[9]  = j + 0x30;
                            key[10] = k + 0x30;
                            key[11] = l + 0x30;
                            key[12] = m + 0x30;
                            if(verifyKey(key) == true) {
                              cout << "Valid key: " << key << endl;
                            //} else {
                            //  cout << "Invalid key: " << key << endl;
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
Quote from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.

MyndFyre

OK so you're running a loop with 10 trillion iterations.  Increment/comparison is 2 instructions per iteration.

You have 13 addition operations there.

You also have 13 assignment operations there.

Since you're using an array you'll have to go to memory; you can't use registers to store what's being assigned.  There are also too many variables to use registers to do the temporary additions.

That's 28 operations per iteration, or 280 trillion operations.

If you manage to run this at one clock cycle per instruction without any other preemption or task switching, you'll be running it for ~116666.67 seconds, roughly 1945 minutes, or 32 hours.

There has GOT to be a better way to come up with a CD key.

I'm curious: are you trying to bruteforce all of Starcraft's possible CD keys?
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

rabbit

while(true)
{
unsigned long long key = 0;
if(functionToCheckValidity(key) == true)
printf("%013d\n", key);

key++;

if(key == 9999999999999)
break;
}

-.-
Note that it's untested...and I don't really care either way, so what may come of this, I don't know.
Grif: Yeah, and the people in the red states are mad because the people in the blue states are mean to them and want them to pay money for roads and schools instead of cool things like NASCAR and shotguns.  Also, there's something about ketchup in there.

Kp

You realize that's a rather silly way of approaching this, right? :)  First, you'll only identify keys which can be used to install Starcraft - most of the keys you identify won't work on battle.net, never have, and probably never will.  Second, since the last character is just a verifier, you could shave off the innermost loop by computing the verifier for each possible 12-digit sequence, then outputting the 12-digit sequence + verifier.  Finally, your d loop is wrong.
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

Joe[x86]

#4
QuoteI'm curious: are you trying to bruteforce all of Starcraft's possible CD keys?
Exactly.

Thanks Rabbit, forgot all about the long long.
EDIT -
999,999,999,999 is too big for a long long.

Quote from: Kp on October 16, 2005, 10:26 AM
You realize that's a rather silly way of approaching this, right? :) First, you'll only identify keys which can be used to install Starcraft - most of the keys you identify won't work on battle.net, never have, and probably never will. Second, since the last character is just a verifier, you could shave off the innermost loop by computing the verifier for each possible 12-digit sequence, then outputting the 12-digit sequence + verifier. Finally, your d loop is wrong.
*cough* DUHHH. I can't believe I forgot about that. I did it that way when I wrote this in VB, but of course, that took even longer. Also, I can't believe I screwed my d loop up so much. =p

EDIT -
Kp, if I weren't reasonably sure you're a male, I'd say I love you. It now generates arround 10,000 keys per second.

Time to work on decoding the CD-Key to see if its productID is correct!
Quote from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.

Kp

If you're interested in coming up with keys for use on battle.net, there's a faster way.  Skip this generation/decode phase and go straight to generating keys in pre-decomposed form.  You know the productID which Starcraft must have, you know (or should know!) the range of values which are appropriate for the "secret" value, and you don't care about the value for the "magic" part.  So: try keys for productID = Starcraft, magic = counter++, secret in [secret_low, secret_high].  One in every secret_high-secret_low keys generated this way has the potential to be valid on battle.net.  Of course, not all "magic" values are legal (some were never sold, so they're prohibited on the server), and some will have been rendered useless by other people (jailed, banned, muted, etc.).
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

Joe[x86]

Excuse my idioticy, but huh?
Quote from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.

Tazo

Kp, I didn't understand what you said either time.


Joe: can you send me the file when you are done, whatever you have generated? I will host it if you'd like


Arta

What Kp wrote is not indecipherable. Give it some time and thought. Understanding how keys work will make it easier for you to generate them!

Tazo

ty Mangix, do I need to fix the d error?

Yoni


rabbit

Quote from: Arta[vL] on October 16, 2005, 05:37 PM
What Kp wrote is not indecipherable. Give it some time and thought. Understanding how keys work will make it easier for you to generate them!
I understood it, I just don't know how to do it.

@Joe: Hence "unsigned".  I'm not exactly sure of the size, but that will increase the bound anyway.
Grif: Yeah, and the people in the red states are mad because the people in the blue states are mean to them and want them to pay money for roads and schools instead of cool things like NASCAR and shotguns.  Also, there's something about ketchup in there.

Tazo

I don't even understand how keys work, so its hard to understand what Kp is saying.. Point out the magic, secret, and low_high things for me in this?

verifyKey(string key) {
  int v, c, n, n2, i;
  v = 3;
  for (i = 0; i < 12; i++) {
    c = key[i];
    n = c - 0x30;
    n2 = v * 2;
    n ^= n2;
    v += n;
  }
  if (v % 10 == (key[12] - 0x30)) {
    return true;
  } else {
    return false;
  }
}

Kp

Quote from: Tazo on October 16, 2005, 08:43 PMPoint out the magic, secret, and low_high things for me in this?

No.
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!