Advertisement
BloodknightStudios

Untitled

Jul 14th, 2014
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.97 KB | None | 0 0
  1. #include <iostream>
  2. #include <sstream>
  3. #include <fstream>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <time.h>
  7. #include <string>
  8.  
  9. #define SQLITE_ENABLE_UPDATE_DELETE_LIMIT 1
  10. #include "sqlite3.h"
  11.  
  12. #include "genfunc.h"
  13.  
  14. using namespace std;
  15. #define LOWER 0
  16. #define UPPER 1
  17. #define uint unsigned int
  18.  
  19. class Time{
  20. time_t currentTime;
  21. public:
  22. Time(){
  23. time( &currentTime );
  24. }
  25. void printTime(){
  26. cout << asctime( localtime( &currentTime));
  27. }
  28. };
  29.  
  30. //****************************************************
  31. // # = letter()
  32. // ~ = Alphanum()
  33. // $ = Algorithma() %7
  34. // % = Algorithmb() %8
  35. // ^ = Algorithmc() %9
  36. // £ = Alphaspecial %26
  37. //***************************************************
  38.  
  39. //***************************************************
  40. // used key templates
  41. // "##$#$-#$#^~-#%#^$-#~#%%-#^~^#-#%#^$-#$#^~" test product keys
  42. //
  43.  
  44. string int_to_string(long i){
  45. stringstream out;
  46. out << i;
  47. return out.str();
  48. }
  49.  
  50. // DATABASE DATA
  51. sqlite3 *db;
  52. char *zErrMsg = 0;
  53. int rc=0;
  54.  
  55.  
  56.  
  57. // FORWARD DECLARATIONS
  58. //static int callback(void *NotUsed, int column, char **data, char **azColName);
  59. void generate(string keytemp);
  60.  
  61. int main(){
  62. Time startTime;
  63. // FILESTREAM DATA
  64. ofstream mysqlfile;
  65. mysqlfile.open ("makedbs.sql");
  66.  
  67. srand(time(NULL));
  68. string keytemp ("##$#$-#$#^~-#%#^$-#~#%%-#^~^#-#%#^$-#$#^~");
  69. int numkeys=500;
  70.  
  71. mysqlfile<<"BEGIN;"<<endl;
  72. mysqlfile<<"CREATE table productkeys (ID INTEGER PRIMARY KEY AUTOINCREMENT, keydata varchar(50), sort varchar(5));"<<endl;
  73. mysqlfile<<"CREATE table newkeys (ID INTEGER PRIMARY KEY AUTOINCREMENT, keydata varchar(50), sort varchar(5));"<<endl;
  74.  
  75. // OPEN DATABASE
  76. rc = sqlite3_open("ProdKeys.db3", &db);
  77. if ( rc ) {
  78. cout<<"Can't open database: "<<sqlite3_errmsg(db)<<endl;
  79. sqlite3_close(db);
  80. return EXIT_FAILURE;
  81. }
  82.  
  83.  
  84. for (int x=1;x<=numkeys;x++) {
  85. string str =keytemp;
  86. int alga=0, algb=0, algc=0, alphaspec=0;
  87. int algaused=0, algbused=0, algcused=0;//, alphaspecused=0;
  88. int algatot=0, algbtot=0, algctot=0, alphaspectot=0;
  89.  
  90. for (uint i=0; i < str.length(); i++){
  91. if (keytemp[i]=='$') alga++;
  92. if (keytemp[i]=='%') algb++;
  93. if (keytemp[i]=='^') algc++;
  94. if (keytemp[i]=='#') alphaspec++;
  95. }
  96. for (uint i=0; i < str.length(); i++){
  97.  
  98. if (keytemp[i]=='@') {
  99. str[i]=gennum();
  100. }
  101.  
  102. if (keytemp[i]=='#'){
  103. string test;
  104. test[0]=genalpha(UPPER);
  105. str[i]=test[0];
  106. alphaspectot+=(int(test[0])-65);
  107. }
  108.  
  109. if (keytemp[i]=='~') {
  110. str[i]=genalphanum(UPPER);
  111. }
  112.  
  113. if (keytemp[i]=='$'){
  114. if (algaused==(alga-1)) {
  115. string strtmpa=int_to_string(7-(algatot%7));
  116. str[i]=strtmpa[0];
  117. algatot+=7-(algatot%7);
  118. }else{
  119. int tmp = ((rand()%9)+1); //gennum();
  120. algatot+=tmp;
  121. string strtmpb=int_to_string(tmp);
  122. str[i]=strtmpb[0];
  123. algaused++;
  124. }
  125. }
  126.  
  127. if (keytemp[i]=='%'){
  128. if (algbused==(algb-1)) {
  129. string strtmpa=int_to_string(8-(algbtot%8));
  130. str[i]=strtmpa[0];
  131. algbtot+=8-(algbtot%8);
  132. }else{
  133. int tmp = ((rand()%9)+1); //gennum();
  134. algbtot+=tmp;
  135. string strtmpb=int_to_string(tmp);
  136. str[i]=strtmpb[0];
  137. algbused++;
  138. }
  139. }
  140. if (keytemp[i]=='^'){
  141. if (algcused==(algc-1)) {
  142. string strtmpa=int_to_string(9-(algctot%9));
  143. str[i]=strtmpa[0];
  144. algctot+=9-(algctot%9);
  145. }else{
  146. int tmp = ((rand()%9)+1); //gennum();
  147. algctot+=tmp;
  148. string strtmpb=int_to_string(tmp);
  149. str[i]=strtmpb[0];
  150. algcused++;
  151. }
  152. }
  153. if (keytemp[i]=='£'){
  154.  
  155. str[i]='Z';
  156.  
  157. }
  158. if (keytemp[i]=='-'){
  159. str[i]='-';
  160. }
  161. }
  162. string sql_insert = "INSERT into productkeys (keydata, sort) values ('";
  163. //sql_insert += int_to_string(loop+1);
  164. //sql_insert += ", '";
  165. sql_insert += str;
  166. sql_insert += "', '";
  167. sql_insert += alphanum[rand()%36];
  168. sql_insert += "');";
  169.  
  170. mysqlfile<<sql_insert<<endl;
  171.  
  172.  
  173. //cout<<str<<" A = "<<algatot%7 <<" B = "<<algbtot%8 <<" C = "<<algctot%9<<endl;
  174. }
  175.  
  176.  
  177. mysqlfile<<"COMMIT;"<<endl;
  178.  
  179.  
  180. /*
  181. // CREATE TABLE
  182. rc = sqlite3_exec(db, "CREATE table productkeys (ID INTEGER PRIMARY KEY AUTOINCREMENT, keydata varachar(100), sort varachar(5));", callback, 0, &zErrMsg);
  183. if ( rc!=SQLITE_OK ) {
  184. cout<<"oops 1"<<zErrMsg<<endl;
  185. sqlite3_free(zErrMsg);
  186. }
  187. rc = sqlite3_exec(db, "CREATE table newkeys (ID INTEGER PRIMARY KEY AUTOINCREMENT, keydata varachar(100), sort varachar(5));", callback, 0, &zErrMsg);
  188. if ( rc!=SQLITE_OK ) {
  189. cout<<"oops 2"<<zErrMsg<<endl;
  190. sqlite3_free(zErrMsg);
  191. }
  192. rc = sqlite3_exec(db, sql_insert.c_str(), callback, 0, &zErrMsg);
  193. if ( rc!=SQLITE_OK ) {
  194. //cout<<"SQL error: see error.log for details"<<endl;
  195. sqlite3_free(zErrMsg);
  196. }
  197. */
  198.  
  199.  
  200. Time endTime;
  201. startTime.printTime();
  202. endTime.printTime();
  203.  
  204. return 0;
  205. }
  206.  
  207. void generate(string keytemp){
  208. string str =keytemp;
  209. int alga=0, algb=0, algc=0, alphaspec=0;
  210. int algaused=0, algbused=0, algcused=0;//, alphaspecused=0;
  211. int algatot=0, algbtot=0, algctot=0, alphaspectot=0;
  212.  
  213. for (uint i=0; i < str.length(); i++){
  214. if (keytemp[i]=='$') alga++;
  215. if (keytemp[i]=='%') algb++;
  216. if (keytemp[i]=='^') algc++;
  217. if (keytemp[i]=='#') alphaspec++;
  218. }
  219. for (uint i=0; i < str.length(); i++){
  220.  
  221. if (keytemp[i]=='@') {
  222. str[i]=gennum();
  223. }
  224.  
  225. if (keytemp[i]=='#'){
  226. string test;
  227. test[0]=genalpha(UPPER);
  228. str[i]=test[0];
  229. alphaspectot+=(int(test[0])-65);
  230. }
  231.  
  232. if (keytemp[i]=='~') {
  233. str[i]=genalphanum(UPPER);
  234. }
  235.  
  236. if (keytemp[i]=='$'){
  237. if (algaused==(alga-1)) {
  238. string strtmpa=int_to_string(7-(algatot%7));
  239. str[i]=strtmpa[0];
  240. algatot+=7-(algatot%7);
  241. }else{
  242. int tmp = ((rand()%9)+1); //gennum();
  243. algatot+=tmp;
  244. string strtmpb=int_to_string(tmp);
  245. str[i]=strtmpb[0];
  246. algaused++;
  247. }
  248. }
  249.  
  250. if (keytemp[i]=='%'){
  251. if (algbused==(algb-1)) {
  252. string strtmpa=int_to_string(8-(algbtot%8));
  253. str[i]=strtmpa[0];
  254. algbtot+=8-(algbtot%8);
  255. }else{
  256. int tmp = ((rand()%9)+1); //gennum();
  257. algbtot+=tmp;
  258. string strtmpb=int_to_string(tmp);
  259. str[i]=strtmpb[0];
  260. algbused++;
  261. }
  262. }
  263. if (keytemp[i]=='^'){
  264. if (algcused==(algc-1)) {
  265. string strtmpa=int_to_string(9-(algctot%9));
  266. str[i]=strtmpa[0];
  267. algctot+=9-(algctot%9);
  268. }else{
  269. int tmp = ((rand()%9)+1); //gennum();
  270. algctot+=tmp;
  271. string strtmpb=int_to_string(tmp);
  272. str[i]=strtmpb[0];
  273. algcused++;
  274. }
  275. }
  276. if (keytemp[i]=='£'){
  277.  
  278. str[i]='Z';
  279.  
  280. }
  281. if (keytemp[i]=='-'){
  282. str[i]='-';
  283. }
  284. }
  285. string sql_insert = "INSERT into productkeys (keydata, sort) values ('";
  286. //sql_insert += int_to_string(loop+1);
  287. //sql_insert += ", '";
  288. sql_insert += str;
  289. sql_insert += "', '";
  290. sql_insert += alphanum[rand()%36];
  291. sql_insert += "');";
  292.  
  293. //mysqlfile<<sql_insert<<endl;
  294. /*
  295. rc = sqlite3_exec(db, sql_insert.c_str(), callback, 0, &zErrMsg);
  296. if ( rc!=SQLITE_OK ) {
  297. //cout<<"SQL error: see error.log for details"<<endl;
  298. sqlite3_free(zErrMsg);
  299. }*/
  300. //cout<<str<<" A = "<<algatot%7 <<" B = "<<algbtot%8 <<" C = "<<algctot%9<<endl;
  301. }
  302.  
  303. /*
  304. static int callback(void *NotUsed, int column, char **data, char **azColName){
  305. int i;
  306. for (i=0; i<column; i++) {
  307. //string dataout = data[i] ? data[i] : "NULL";
  308. //cout<<azColName[i]<<"="<<dataout<<" ";
  309. }
  310. cout<<endl;
  311. return 0;
  312. }
  313. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement