Click here to Skip to main content
15,897,704 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi,

im trying to make a program that will only run for 50 times.
here's the sample of my code

config.ini
C++
[Trial]
Value=1

main.cpp
C++
string str = parse.get <std::string>("Trial.Value");
    int i;
    stringstream(str) >> i;
    
    if(i >= 51){
         exit(1);
         }else{

 
    int a = i + 1;    // problem here is it can only work once, after that it will                  
                      //stop adding. so im stuck with Value=2
    
    stringstream ss;
    ss << a;
    
    ofstream file("config.ini");
    file << "[Trial]";
    file << "\nValue=";
    file << (ss, ios::ate); //problem here (i think)..no matter what value i put
                            // in sample.ini for example Value=25 ...the output 
                            //will still be Value=2

    file.close();


what i want to do here is every time i will open this program it will add +1 in Value=1 until it reaches Value=50..please any way to do this?

thanks in advance
Posted
Updated 19-Aug-12 10:33am
v5

1 solution

Clearly, this is not a hard scheme to crack. Given that you don't read it as an ini file, why not write a random stream of bytes, and come up with a way that the content all changes, so no-one can tell which byte is the one you're reading ( for example, use a hash and encode your sequence somehow so that it's not 1-50, for example if you create a random number generated with a hard coded seed, you can reproduce that sequence to count to what the 50th value is ).

I don't know off hand why this is not working, but if you change your code to something that might actually survive attempts to crack it, along the way you will probably find that you'll write something that works.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 19-Aug-12 23:00pm    
Fair enough, my 5.
And I think the scheme devised by OP is just a pretty bad idea...
--SA
Ronni2013 20-Aug-12 0:25am    
thank you sir.. i just want to try to start from this(its just an example anyway)..yes i really plan to make it hard to crack..thanks again

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900