Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <sstream>
- #include <fstream>
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #include <string>
- #define SQLITE_ENABLE_UPDATE_DELETE_LIMIT 1
- #include "sqlite3.h"
- #include "genfunc.h"
- using namespace std;
- #define LOWER 0
- #define UPPER 1
- #define uint unsigned int
- class Time{
- time_t currentTime;
- public:
- Time(){
- time( ¤tTime );
- }
- void printTime(){
- cout << asctime( localtime( ¤tTime));
- }
- };
- //****************************************************
- // # = letter()
- // ~ = Alphanum()
- // $ = Algorithma() %7
- // % = Algorithmb() %8
- // ^ = Algorithmc() %9
- // £ = Alphaspecial %26
- //***************************************************
- //***************************************************
- // used key templates
- // "##$#$-#$#^~-#%#^$-#~#%%-#^~^#-#%#^$-#$#^~" test product keys
- //
- string int_to_string(long i){
- stringstream out;
- out << i;
- return out.str();
- }
- // DATABASE DATA
- sqlite3 *db;
- char *zErrMsg = 0;
- int rc=0;
- // FORWARD DECLARATIONS
- //static int callback(void *NotUsed, int column, char **data, char **azColName);
- void generate(string keytemp);
- int main(){
- Time startTime;
- // FILESTREAM DATA
- ofstream mysqlfile;
- mysqlfile.open ("makedbs.sql");
- srand(time(NULL));
- string keytemp ("##$#$-#$#^~-#%#^$-#~#%%-#^~^#-#%#^$-#$#^~");
- int numkeys=500;
- mysqlfile<<"BEGIN;"<<endl;
- mysqlfile<<"CREATE table productkeys (ID INTEGER PRIMARY KEY AUTOINCREMENT, keydata varchar(50), sort varchar(5));"<<endl;
- mysqlfile<<"CREATE table newkeys (ID INTEGER PRIMARY KEY AUTOINCREMENT, keydata varchar(50), sort varchar(5));"<<endl;
- // OPEN DATABASE
- rc = sqlite3_open("ProdKeys.db3", &db);
- if ( rc ) {
- cout<<"Can't open database: "<<sqlite3_errmsg(db)<<endl;
- sqlite3_close(db);
- return EXIT_FAILURE;
- }
- for (int x=1;x<=numkeys;x++) {
- string str =keytemp;
- int alga=0, algb=0, algc=0, alphaspec=0;
- int algaused=0, algbused=0, algcused=0;//, alphaspecused=0;
- int algatot=0, algbtot=0, algctot=0, alphaspectot=0;
- for (uint i=0; i < str.length(); i++){
- if (keytemp[i]=='$') alga++;
- if (keytemp[i]=='%') algb++;
- if (keytemp[i]=='^') algc++;
- if (keytemp[i]=='#') alphaspec++;
- }
- for (uint i=0; i < str.length(); i++){
- if (keytemp[i]=='@') {
- str[i]=gennum();
- }
- if (keytemp[i]=='#'){
- string test;
- test[0]=genalpha(UPPER);
- str[i]=test[0];
- alphaspectot+=(int(test[0])-65);
- }
- if (keytemp[i]=='~') {
- str[i]=genalphanum(UPPER);
- }
- if (keytemp[i]=='$'){
- if (algaused==(alga-1)) {
- string strtmpa=int_to_string(7-(algatot%7));
- str[i]=strtmpa[0];
- algatot+=7-(algatot%7);
- }else{
- int tmp = ((rand()%9)+1); //gennum();
- algatot+=tmp;
- string strtmpb=int_to_string(tmp);
- str[i]=strtmpb[0];
- algaused++;
- }
- }
- if (keytemp[i]=='%'){
- if (algbused==(algb-1)) {
- string strtmpa=int_to_string(8-(algbtot%8));
- str[i]=strtmpa[0];
- algbtot+=8-(algbtot%8);
- }else{
- int tmp = ((rand()%9)+1); //gennum();
- algbtot+=tmp;
- string strtmpb=int_to_string(tmp);
- str[i]=strtmpb[0];
- algbused++;
- }
- }
- if (keytemp[i]=='^'){
- if (algcused==(algc-1)) {
- string strtmpa=int_to_string(9-(algctot%9));
- str[i]=strtmpa[0];
- algctot+=9-(algctot%9);
- }else{
- int tmp = ((rand()%9)+1); //gennum();
- algctot+=tmp;
- string strtmpb=int_to_string(tmp);
- str[i]=strtmpb[0];
- algcused++;
- }
- }
- if (keytemp[i]=='£'){
- str[i]='Z';
- }
- if (keytemp[i]=='-'){
- str[i]='-';
- }
- }
- string sql_insert = "INSERT into productkeys (keydata, sort) values ('";
- //sql_insert += int_to_string(loop+1);
- //sql_insert += ", '";
- sql_insert += str;
- sql_insert += "', '";
- sql_insert += alphanum[rand()%36];
- sql_insert += "');";
- mysqlfile<<sql_insert<<endl;
- //cout<<str<<" A = "<<algatot%7 <<" B = "<<algbtot%8 <<" C = "<<algctot%9<<endl;
- }
- mysqlfile<<"COMMIT;"<<endl;
- /*
- // CREATE TABLE
- rc = sqlite3_exec(db, "CREATE table productkeys (ID INTEGER PRIMARY KEY AUTOINCREMENT, keydata varachar(100), sort varachar(5));", callback, 0, &zErrMsg);
- if ( rc!=SQLITE_OK ) {
- cout<<"oops 1"<<zErrMsg<<endl;
- sqlite3_free(zErrMsg);
- }
- rc = sqlite3_exec(db, "CREATE table newkeys (ID INTEGER PRIMARY KEY AUTOINCREMENT, keydata varachar(100), sort varachar(5));", callback, 0, &zErrMsg);
- if ( rc!=SQLITE_OK ) {
- cout<<"oops 2"<<zErrMsg<<endl;
- sqlite3_free(zErrMsg);
- }
- rc = sqlite3_exec(db, sql_insert.c_str(), callback, 0, &zErrMsg);
- if ( rc!=SQLITE_OK ) {
- //cout<<"SQL error: see error.log for details"<<endl;
- sqlite3_free(zErrMsg);
- }
- */
- Time endTime;
- startTime.printTime();
- endTime.printTime();
- return 0;
- }
- void generate(string keytemp){
- string str =keytemp;
- int alga=0, algb=0, algc=0, alphaspec=0;
- int algaused=0, algbused=0, algcused=0;//, alphaspecused=0;
- int algatot=0, algbtot=0, algctot=0, alphaspectot=0;
- for (uint i=0; i < str.length(); i++){
- if (keytemp[i]=='$') alga++;
- if (keytemp[i]=='%') algb++;
- if (keytemp[i]=='^') algc++;
- if (keytemp[i]=='#') alphaspec++;
- }
- for (uint i=0; i < str.length(); i++){
- if (keytemp[i]=='@') {
- str[i]=gennum();
- }
- if (keytemp[i]=='#'){
- string test;
- test[0]=genalpha(UPPER);
- str[i]=test[0];
- alphaspectot+=(int(test[0])-65);
- }
- if (keytemp[i]=='~') {
- str[i]=genalphanum(UPPER);
- }
- if (keytemp[i]=='$'){
- if (algaused==(alga-1)) {
- string strtmpa=int_to_string(7-(algatot%7));
- str[i]=strtmpa[0];
- algatot+=7-(algatot%7);
- }else{
- int tmp = ((rand()%9)+1); //gennum();
- algatot+=tmp;
- string strtmpb=int_to_string(tmp);
- str[i]=strtmpb[0];
- algaused++;
- }
- }
- if (keytemp[i]=='%'){
- if (algbused==(algb-1)) {
- string strtmpa=int_to_string(8-(algbtot%8));
- str[i]=strtmpa[0];
- algbtot+=8-(algbtot%8);
- }else{
- int tmp = ((rand()%9)+1); //gennum();
- algbtot+=tmp;
- string strtmpb=int_to_string(tmp);
- str[i]=strtmpb[0];
- algbused++;
- }
- }
- if (keytemp[i]=='^'){
- if (algcused==(algc-1)) {
- string strtmpa=int_to_string(9-(algctot%9));
- str[i]=strtmpa[0];
- algctot+=9-(algctot%9);
- }else{
- int tmp = ((rand()%9)+1); //gennum();
- algctot+=tmp;
- string strtmpb=int_to_string(tmp);
- str[i]=strtmpb[0];
- algcused++;
- }
- }
- if (keytemp[i]=='£'){
- str[i]='Z';
- }
- if (keytemp[i]=='-'){
- str[i]='-';
- }
- }
- string sql_insert = "INSERT into productkeys (keydata, sort) values ('";
- //sql_insert += int_to_string(loop+1);
- //sql_insert += ", '";
- sql_insert += str;
- sql_insert += "', '";
- sql_insert += alphanum[rand()%36];
- sql_insert += "');";
- //mysqlfile<<sql_insert<<endl;
- /*
- rc = sqlite3_exec(db, sql_insert.c_str(), callback, 0, &zErrMsg);
- if ( rc!=SQLITE_OK ) {
- //cout<<"SQL error: see error.log for details"<<endl;
- sqlite3_free(zErrMsg);
- }*/
- //cout<<str<<" A = "<<algatot%7 <<" B = "<<algbtot%8 <<" C = "<<algctot%9<<endl;
- }
- /*
- static int callback(void *NotUsed, int column, char **data, char **azColName){
- int i;
- for (i=0; i<column; i++) {
- //string dataout = data[i] ? data[i] : "NULL";
- //cout<<azColName[i]<<"="<<dataout<<" ";
- }
- cout<<endl;
- return 0;
- }
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement