Possibly a stupid question.

Status
Not open for further replies.

Chewybacca

Member
Original poster
member
Joined
Aug 6, 2011
Posts
18
Reaction score
0
Points
0
In my quest to create a (fake) keygen generator I have stumbled upon a little problem, as we all know (not from experience, of course!) keygens usually provide their output in the form of XXXX-XXXX-XXXX-XXXX.

I am using c++ for this and am creating a vector that will hold a variable value, this value will be input by me in the main .exe file, for example.

The code would look like this:
int a;
cin >> a;
vector<int> numchar(a);

I understand this will only allow numbers to be placed in any of the vector "slots" however I am trying to take this one step at a time.

The problem I am hoping you wonderful people could help me with is how I would get around to adding these random variables to my vector.

Currently I am thinking of a while loop that would look like this

int x = 0;
while (x != a)
{
This is where I am stuck, I would use the rand() 10% to get my number between 0 and 9 to put in the vector, the while loop would then add one to x.

The problem is when it loops it will just override the current value in the vector, as I am unsure of how to make it go to the next "place" in the vector.

Thanks in advance.
 

Chewybacca

Member
Original poster
member
Joined
Aug 6, 2011
Posts
18
Reaction score
0
Points
0
Good point, I should of put c++ into the title, I apologize and will make sure for next time :(
 

Serb

Based
veteran
old school
senior
member
Joined
Aug 1, 2010
Posts
2,853
Reaction score
1,173
Points
194
Good point, I should of put c++ into the title, I apologize and will make sure for next time :(

Why would you use c++ to make a fake keygen? VB is always the way to go regarding tools like this.
 

Chewybacca

Member
Original poster
member
Joined
Aug 6, 2011
Posts
18
Reaction score
0
Points
0
Because in general c++ is a much more powerful and useful language, and it's not so much that I want a fake keygen generator, it's that I want to do this in c++, it's easy enough to do what i'm asking in VB (I believe) but for me, and for this, the journey is more important than the ending, if that makes sense at all.

However even if this where not the case, would I be able to get a solution, even if i'm wrong for using c++ to do this.
 

Flip

Old School
old school
member
Joined
Jul 23, 2009
Posts
263
Reaction score
69
Points
108
If vectors are confusing you why use a vector? You could accomplish the same thing by putting the values in an array.

Just make an array (or four, one for each 'XXXX' block) and print them out with the formatting you want.

Couldn't you also just print out a bunch of numbers using a Random() function and format it properly?

Edit: I'm pretty sure this is what you want

Code:
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
int random, chunkSize, size;

cout << "Insert size of 'chunks'" << endl;
cin >> chunkSize;
cout << "Insert number of " << chunkSize << " digit 'chunks'" << endl;
cin >> size;

for(int i = 0; i < size; i++)
{
    for(int j = 0; j < chunkSize; j++)
    {
    random = (rand()%10);
    cout << random;
    }
if(i == size - 1)
{
cout << endl;
}
else
{
cout << "-";
}
}

cout << endl;
return 0;
}
output :

Code:
Insert size of 'chunks'
4
Insert number of 4 digit 'chunks'
4
8835-1709-2697-4053
 
Status
Not open for further replies.