void ATextGenerator::generateRandomWord(AOutputBuffer& target, size_t len /* = 0x1 */) { if (len < 1) return; //a_Lead with consonant --len; AString str, strLast("-", 1); generateRandomString(str, 1, AConstant::CHARSET_LOWERCASE_CONSONANTS); str.makeUpper(); target.append(str); bool boolConsonant = false; while (len > 0) { if (boolConsonant) { //a_Add a consonant do { str.clear(); generateRandomString(str, 1, AConstant::CHARSET_LOWERCASE_CONSONANTS); } while(str.at(0) == strLast.at(0) && ARandomNumberGenerator::get().nextU1() > 220); target.append(str); --len; strLast = str; boolConsonant = false; } else { //a_Add a vowel int twice = 0; do { do { str.clear(); generateRandomString(str, 1, AConstant::CHARSET_LOWERCASE_VOWELS); } while(str.at(0) == strLast.at(0) && ARandomNumberGenerator::get().nextU1() > 130); target.append(str); --len; strLast = str; } while (len > 0 && twice++ < 2 && ARandomNumberGenerator::get().nextU1() > 225); boolConsonant = true; } } }
char* device_PRT::getTempFileName() { DWORD dwRetVal = 0; UINT uRetVal = 0; char* szTempFileName = (char*)malloc(MAX_PATH); TCHAR lpTempPathBuffer[MAX_PATH]; // Gets the temp path env string (no guarantee it's a valid path). dwRetVal = GetTempPath(MAX_PATH, // length of the buffer lpTempPathBuffer); // buffer for path if (dwRetVal < MAX_PATH - 11 && (dwRetVal != 0)) { strcat(lpTempPathBuffer, "vDos\\"); if (!CreateDirectory(lpTempPathBuffer, NULL)) { DWORD lastError = GetLastError(); if (lastError != ERROR_ALREADY_EXISTS) { ErrorDialog("Could not create temp folder '%s'", lpTempPathBuffer); return NULL; } } char prefix[4]; // Generates a temporary file name. uRetVal = GetTempFileName(lpTempPathBuffer, // directory for tmp files generateRandomString(prefix, 3), // temp file name prefix 0, // create unique name szTempFileName); // buffer for name if (uRetVal != 0) { return szTempFileName; } } return NULL; }
FormInputCollectionPtr StaticFormInputGenerator::generateFormFields(QSet<FormFieldDescriptorConstPtr> fields, ExecutionResultConstPtr) const { QList<FormInputPair> inputs; foreach(FormFieldDescriptorConstPtr field, fields) { if (mExcludedFormFields.contains(field->getDomElement()->getId())) { continue; } switch (field->getType()) { case TEXT: inputs.append(FormInputPair(field, InjectionValue(generateRandomString(10)))); break; case BOOLEAN: inputs.append(FormInputPair(field, InjectionValue(randomBool()))); break; case FIXED_INPUT: if(field->getInputOptions().size()>0){ inputs.append(FormInputPair(field, InjectionValue(pickRand(field->getInputOptions())))); break; } default: inputs.append(FormInputPair(field, InjectionValue(QString("")))); } } return FormInputCollectionPtr(new FormInputCollection(inputs)); }
static void testStringSet() { enum { numStrings = 1000 }; HashSet<std::string> set; std::vector<std::string> strings; srand(0); for(Uptr i = 0;i < numStrings;++i) { while(true) { std::string randomString = generateRandomString(); bool alreadySawString = false; for(const std::string& string : strings) { if(string == randomString) { alreadySawString = true; break; } } if(!alreadySawString) { strings.push_back(std::move(randomString)); break; } }; } for(Uptr i = 0;i < strings.size();++i) { errorUnless(set.add(strings[i])); errorUnless(!set.add(strings[i])); for(Uptr j = 0;j < strings.size();++j) { const bool expectedContains = j <= i; errorUnless(set.contains(strings[j]) == expectedContains); } } for(Uptr i = 0;i < strings.size();++i) { errorUnless(set.remove(strings[i])); errorUnless(!set.remove(strings[i])); for(Uptr j = 0;j < strings.size();++j) { const bool expectedContains = j > i; errorUnless(set.contains(strings[j]) == expectedContains); } } }
void GOConstraint::init() { if (Game::instance->editorMode && !hasID) { id = "cnst_" + generateRandomString(5); bindLua(); } constraint = NULL; secondObject = NULL; owner = NULL; needRecreateConstraint = true; Game::instance->constraints.push_back(this); }
static void renameSeveralTimes(string &from, int nTimes, const string mpt) { plfs_error_t ret; for (int i = 0; i < nTimes; i++) { string to = mpt + generateRandomString(); ret = plfs_rename(from.c_str(), to.c_str()); CPPUNIT_ASSERT_EQUAL(0, (int)ret); ret = plfs_access(to.c_str(), F_OK); CPPUNIT_ASSERT_EQUAL(0, (int)ret); from = to; } }
void CommonTestsSuite::test_generateRandomString() { map<string, string> strings; for (uint32_t i = 0; i < 16384; i++) { string randString = generateRandomString(16); //we don't want to increment tests count //That is why we use TS_ASSERT_NO_INCREMENT TS_ASSERT_NO_INCREMENT(randString != ""); if (strings.find(randString) != strings.end()) { TS_ASSERT(false); } strings[randString]; } //Ok, treat all this 16384 tests as one test by doing a dummy test TS_ASSERT(true); }
void checkVariableTest(edict_t *ent, int client, int idx) { if (checkvarcmds_enable) { if (idx >= maxcheckvars) { idx = 0; } if (maxcheckvars) { proxyinfo[client].checkvar_idx = idx; generateRandomString(proxyinfo[client].hack_checkvar, RANDOM_STRING_LENGTH); sprintf(buffer, "%s $%s\n", proxyinfo[client].hack_checkvar, checkvarList[idx].variablename); stuffcmd(ent, buffer); idx++; } } else { idx = 0; } addCmdQueue(client, QCMD_CHECKVARTESTS, (float) checkvar_poll_time, idx, 0); }
void PlfsUnit::dirTest() { string path = mountpoint + "/dirtest1"; const char *pathname = path.c_str(); set<string> dents; set<string> readres; set<string>::iterator it; plfs_error_t ret; ret = plfs_mkdir(pathname, PLFSUNIT_DEFAULT_DIR_MODE); CPPUNIT_ASSERT_EQUAL(0, (int)ret); for (int i = 0; i < 100; i++) { string subdir = generateRandomString(); pair<set<string>::iterator, bool> result; result = dents.insert(subdir); if (result.second) { string fullpath = path + subdir; ret = plfs_mkdir(fullpath.c_str(), PLFSUNIT_DEFAULT_DIR_MODE); CPPUNIT_ASSERT_EQUAL(0, (int)ret); } } ret = plfs_rmdir(pathname); CPPUNIT_ASSERT_EQUAL(PLFS_ENOTEMPTY, ret); ret = plfs_readdir(pathname, &readres); CPPUNIT_ASSERT_EQUAL(0, (int)ret); for (it=readres.begin() ; it != readres.end(); it++) { if (*it == "." || *it == "..") continue; string fullpath = path + "/" + *it; ret = plfs_rmdir(fullpath.c_str()); CPPUNIT_ASSERT_EQUAL(0, (int)ret); dents.erase("/" + *it); } CPPUNIT_ASSERT(dents.empty()); ret = plfs_rmdir(pathname); CPPUNIT_ASSERT_EQUAL(0, (int)ret); }
void passwordGenerator() { Menu menu; menu.type = MENUTYPE_FKEYS; menu.title = (char*)"Password Generator"; menu.height = 7; MenuItem items[6]; int length = 10; int seed = RTC_GetTicks() * (GetMainBatteryVoltage(1) % 100); char lstr[10]; items[1].text = (char*)"Include symbols"; items[1].type = MENUITEM_CHECKBOX; items[2].text = (char*)"Include numbers"; items[2].type = MENUITEM_CHECKBOX; items[2].value = MENUITEM_VALUE_CHECKED; items[3].text = (char*)"Include uppercase"; items[3].type = MENUITEM_CHECKBOX; items[3].value = MENUITEM_VALUE_CHECKED; items[4].text = (char*)"Include confusable"; items[4].type = MENUITEM_CHECKBOX; items[4].value = MENUITEM_VALUE_CHECKED; items[5].text = (char*)"Memorable vowel mix"; items[5].type = MENUITEM_CHECKBOX; menu.numitems = 6; menu.items = items; while(1) { drawFkeyLabels(0x03B3, 0, 0, 0, 0, 0x0184); // FILE, EXE (white) itoa(length, (unsigned char*)lstr); char t[20]; strcpy(t, "Length: "); strcat(t, lstr); items[0].text = t; switch(doMenu(&menu)) { case MENU_RETURN_EXIT: return; case MENU_RETURN_SELECTION: if(menu.selection > 1) items[menu.selection-1].value = !items[menu.selection-1].value; else { Selector sel; sel.min = 6; sel.value = length; sel.max = 30; sel.cycle = 1; sel.title = (char*)"Password Generator"; sel.subtitle = (char*)"Length"; if(doSelector(&sel) == SELECTOR_RETURN_SELECTION) { length = sel.value; } } break; case KEY_CTRL_F1: { Selector sel; sel.min = 1; sel.value = 10; sel.max = 1000; sel.cycle = 1; sel.title = (char*)"Generate to file"; sel.subtitle = (char*)"Number of passwords"; if(doSelector(&sel) != SELECTOR_RETURN_SELECTION) break; SetBackGround(10); drawScreenTitle("Generate to file", "Filename:"); char newname[MAX_NAME_SIZE]; newname[0] = 0; textInput input; input.forcetext=1; input.symbols = 0; input.charlimit=MAX_NAME_SIZE; input.buffer = (char*)newname; int inscreen = 1; while(inscreen) { input.key=0; int res = doTextInput(&input); if (res==INPUT_RETURN_EXIT) break; // user aborted else if (res==INPUT_RETURN_CONFIRM) { inscreen = 0; } } if(inscreen) break; char newfilename[MAX_FILENAME_SIZE]; strcpy(newfilename, SMEM_PREFIX); strcat(newfilename, newname); strcat(newfilename, ".txt"); unsigned short pFile[0x10A]; Bfile_StrToName_ncpy(pFile, newfilename, 0x10A); unsigned int size = 1; int ntry = 0; while(ntry < 2) { ntry++; int BCEres = Bfile_CreateEntry_OS(pFile, CREATEMODE_FILE, &size); if(BCEres >= 0) { int hFile = Bfile_OpenFile_OS(pFile, READWRITE, 0); // Get handle if(hFile >= 0) { char password[35]; char line[37]; for(int i = 0; i < sel.value; i++) { generateRandomString(password, length, items[1].value, items[2].value, items[3].value, items[4].value, items[5].value, &seed); sprintf(line, "%s\r\n", password); Bfile_WriteFile_OS(hFile, line, length+2); } Bfile_CloseFile_OS(hFile); } else AUX_DisplayErrorMessage(0x2B); break; } else if(ntry < 2) { // File creation probably failed due to the presence of a file with the same name if(overwriteFilePrompt(newfilename)) Bfile_DeleteEntry(pFile); else break; } else AUX_DisplayErrorMessage(0x2B); } break; } case KEY_CTRL_F6: int inscreen = 1; while(inscreen) { Bdisp_AllClr_VRAM(); drawScreenTitle("Password Generator", "Generated passwords:"); textArea text; text.type = TEXTAREATYPE_INSTANT_RETURN; text.scrollbar = 0; text.y = 48+3; text.lineHeight = 20; textElement e[5]; char passwords[5][35]; for(int i = 0; i < 5; i++) { generateRandomString(passwords[i], length, items[1].value, items[2].value, items[3].value, items[4].value, items[5].value, &seed); e[i].text = passwords[i]; if(i) e[i].newLine = 1; } text.elements = e; text.numelements = 5; doTextArea(&text); drawFkeyLabels(0x036F, 0, 0, 0, 0, 0x02B9); // <, REPEAT (white) while(1) { int key; mGetKey(&key); if(key == KEY_CTRL_F6) break; if(key == KEY_CTRL_F1 || key == KEY_CTRL_EXIT) { inscreen = 0; break; } } } break; } } }
ReverseHashDServer::ReverseHashDServer(quint16 port, QObject *parent) : QObject(parent) { m_pReverseHashDServer = new QWebSocketServer(QStringLiteral("reversehashd"), QWebSocketServer::NonSecureMode, this); QString sFolder = "tmp_server_md5"; m_pBnaProject = new BNAProject(); if(!m_pBnaProject->open(sFolder)){ std::cerr << "Could not open project, try create\n"; m_pBnaProject->setInputBits(128); m_pBnaProject->setOutputBits(440); m_pBnaProject->setDefaultCountNodes(256); m_pBnaProject->create(sFolder); // fill memory for learning BNAMemory *pBNAMemory = m_pBnaProject->getBNAMemory(); for(int i = 0; i < 10000; i++){ BNAMemoryItem *pBNAMemoryItem = pBNAMemory->createItem(); pBNAMemoryItem->output.append(generateRandomString()); pBNAMemoryItem->input = QCryptographicHash::hash(pBNAMemoryItem->output, QCryptographicHash::Md5); pBNAMemory->append(pBNAMemoryItem); } m_pBnaProject->saveBNAMemory(); } // init bna /* * TODO move yto BNA project like export to cpp QDir dir("."); dir.mkpath(path); QString pro_file_content_sources = "SOURCES += \\\r\n"; pro_file_content_sources += "\tmd5revert_helpers.h \\\r\n"; QString pro_file_content_headers = "HEADERS += \\\r\n"; pro_file_content_sources += "\tmd5revert_main.cpp \\\r\n"; pro_file_content_sources += "\tmd5revert_helpers.cpp \\\r\n"; for(int i = 0; i < 440; i++){ QString name = QString::number(i).rightJustified(3, '0'); QString subdir = name[0] + "/" + name[1] + "/" + name[2]; QString d = path + "/" + subdir; dir.mkpath(d); QString filename_bna = d + "/" + name + ".bna"; QString filename_cpp = d + "/" + name + ".cpp"; QString filename_h = d + "/" + name + ".h"; QString filename_dot = d + "/" + name + ".dot"; QFile file(filename_bna); if(!file.exists()){ BNA bna; bna.randomGenerate(128,1,256); bna.save(filename_bna); qDebug() << filename_bna << " - created"; } if(QFile(filename_bna).exists()){ BNA bna; bna.load(filename_bna); bna.exportToCpp(filename_cpp, "func" + name); } if(QFile(filename_bna).exists()){ BNA bna; bna.load(filename_bna); bna.exportToDot(filename_dot, "func" + name); } pro_file_content_sources += "\t" + subdir + "/" + name + ".cpp \\\r\n"; pro_file_content_headers += "\t" + subdir + "/" + name + ".h \\\r\n"; } // write pro file { pro_file_content_sources += "\r\n"; pro_file_content_headers += "\r\n"; QString sDilenameProFile = path + "/md5revert.pro"; QFile file(sDilenameProFile); if (file.exists()) { file.remove(); } if ( !file.open(QIODevice::WriteOnly) ) { qDebug().noquote().nospace() << "Could not write file: " << sDilenameProFile; }else{ QTextStream stream( &file ); stream << "TEMPLATE = app\r\n"; stream << "TARGET = md5revert\r\n"; stream << "QT += core\r\n"; stream << "QT -= gui\r\n"; stream << "\r\n"; stream << "CONFIG += console\r\n"; stream << "CONFIG -= app_bundle\r\n"; stream << "CONFIG += c++11 c++14\r\n"; stream << "\r\n"; stream << "OBJECTS_DIR = tmp/\r\n"; stream << "MOC_DIR = tmp/\r\n"; stream << "RCC_DIR = tmp/\r\n"; stream << "\r\n"; stream << pro_file_content_sources; stream << pro_file_content_headers; } } // init main.cpp this->extractFile(":/res/md5revert_main.cpp", path + "/md5revert_main.cpp"); this->extractFile(":/res/md5revert_helpers.h", path + "/md5revert_helpers.h"); this->extractFile(":/res/md5revert_helpers.cpp", path + "/md5revert_helpers.cpp"); */ if (m_pReverseHashDServer->listen(QHostAddress::Any, port)) { std::cout << "reversehashd listening on port " << port << "\n"; connect(m_pReverseHashDServer, &QWebSocketServer::newConnection, this, &ReverseHashDServer::onNewConnection); connect(m_pReverseHashDServer, &QWebSocketServer::closed, this, &ReverseHashDServer::closed); connect(this, &ReverseHashDServer::sendToAllSignal, this, &ReverseHashDServer::sendToAllSlot); create_cmd_handlers(m_mapCmdHandlers); } m_pTrainingThread = new TrainingThread(this, m_pBnaProject); m_pTrainingThread->start(QThread::LowestPriority); }
void wasmint::TestCaseGenerator::generateFunction() { source_ << "(func "; generateRandomString(); generateInstruction(); source_ << ")"; }
void wasmint::TestCaseGenerator::generateInstruction(const wasm_module::Type* expectedReturnType) { instructions++; TestCaseInstruction* instruction; if (instructions < instructionLimit) { while(true) { std::size_t index = randomInRange(testInstructions.size()); instruction = &testInstructions.at(index); if (expectedReturnType == nullptr) break; if (instruction->returnType == expectedReturnType) break; } } else { if (expectedReturnType == Int32::instance()) { instruction = &leafTestInstructions.at(0); } else if (expectedReturnType == Int64::instance()) { instruction = &leafTestInstructions.at(1); } else if (expectedReturnType == Float32::instance()) { instruction = &leafTestInstructions.at(2); } else if (expectedReturnType == Float64::instance()) { instruction = &leafTestInstructions.at(3); } else { instruction = &leafTestInstructions.at(4); } } source_ << " (" << instruction->name << " "; if (instruction->special) { if (instruction->name == "i32.const") { source_ << randomInRange(1000); } else if (instruction->name == "i64.const") { source_ << randomInRange(1000); } else if (instruction->name == "f32.const") { source_ << randomInRange(1000); } else if (instruction->name == "f64.const") { source_ << randomInRange(1000); } else if (instruction->name == "has_feature") { generateRandomString(); } else if (instruction->name == "get_local") { generateRandomString(); } else if (instruction->name == "set_local") { generateRandomString(); } else if (instruction->name == "label") { generateRandomString(); } else if (instruction->name == "block") { generateRandomString(); } else if (instruction->name == "loop") { generateRandomString(); } else if (instruction->name == "call_import") { generateRandomString(); } else if (instruction->name == "call") { generateRandomString(); } else if (instruction->name == "call_indirect") { generateRandomString(); } else if (instruction->name == "br") { generateRandomString(); } else if (instruction->name == "br_if") { generateRandomString(); } else { std::cerr << "Unknown special instruction during generation " << instruction->name << std::endl; exit(1); } } source_ << " "; if (instructions < instructionLimit) { for (std::size_t i = 0; i < instruction->children.size(); i++) { const Type *expectedChildType = nullptr; if (i < instruction->children.size()) { expectedChildType = instruction->children.at(i); } generateInstruction(expectedChildType); } } source_ << ") "; }
static void testStringMap() { enum { numStrings = 1000 }; HashMap<std::string, U32> map; std::vector<HashMapPair<std::string, U32>> pairs; srand(0); for(Uptr i = 0;i < numStrings;++i) { while(true) { std::string randomString = generateRandomString(); bool alreadySawString = false; for(const HashMapPair<std::string, U32>& pair : pairs) { if(pair.key == randomString) { alreadySawString = true; break; } } if(!alreadySawString) { pairs.emplace_back(std::move(randomString), rand()); break; } }; } for(Uptr i = 0;i < pairs.size();++i) { errorUnless(map.add(pairs[i].key, pairs[i].value)); errorUnless(!map.add(pairs[i].key, pairs[i].value)); for(Uptr j = 0;j < pairs.size();++j) { const U32* valuePtr = map.get(pairs[j].key); if(j <= i) { errorUnless(valuePtr && *valuePtr == pairs[j].value); } else { errorUnless(!valuePtr); } } } for(Uptr i = 0;i < pairs.size();++i) { errorUnless(map.remove(pairs[i].key)); errorUnless(!map.remove(pairs[i].key)); for(Uptr j = 0;j < pairs.size();++j) { const U32* valuePtr = map.get(pairs[j].key); if(j > i) { errorUnless(valuePtr && *valuePtr == pairs[j].value); } else { errorUnless(!valuePtr); } } } }
//a_Complely random number from sm__strNumber void ATextGenerator::generateRandomAlphanum(AOutputBuffer& target, size_t len /* = 0x1 */) { generateRandomString(target, len, AConstant::CHARSET_ALPHANUM); }
int main ( int argc, char* argv[] ) { std::cout << "running....\n"; try { // Create the socket ServerSocket server ( 30000 ); while ( true ) { ServerSocket varServerSocket; server.accept ( varServerSocket ); try { while ( true ) { bool varEncrypt (true); size_t varFound(0); std::string varScope; std::string varHash; std::string varSaltServer; std::string varSaltClient; std::string varPassword; std::string varData; std::string key; //Standard ensure the vars are clean varScope.clear(); varHash.clear(); varSaltClient.clear(); varSaltServer.clear(); varPassword.clear(); varData.clear(); key.clear(); //Standard start buildup //Sent Salt1 which is used as part of the password hashing //-e-scope-hash-salt--input //sha256(salt+password+salt) //Generate and end the salt generateRandomString(varSaltServer, 24); varServerSocket << varSaltServer; //Get and then process Data varServerSocket >> varData; //log(varData); //Check if encrypting or decrypting if(varData.substr(0,2) == "-d" ) { varEncrypt = false; } varData.erase (0,int(varFound)+3); //Check scope (Key set) varFound = varData.find("-"); if (varFound != std::string::npos) { varScope = varData.substr (0,int(varFound)); varData.erase (0,int(varFound)+1); } //Get Hash and Salt to verify connection varFound = varData.find("-"); if (varFound != std::string::npos) { varSaltClient = varData.substr (0,int(varFound)); varData.erase (0,int(varFound)+1); } varFound = varData.find("-"); if (varFound != std::string::npos) { varHash = varData.substr (0,int(varFound)); varData.erase (0,int(varFound)); } //Find termination string and drop everything before it varFound = varData.find("--"); if (varFound != std::string::npos) { varData.erase (0,int(varFound)+2); } //Load the configurations for the scope varPassword = "******"; //Verify the connection //std::string& varHash, std::string& varSaltServer, std::string& varSaltClient, std::string& varPassword if(checkHash2Password(varHash, varSaltServer, varSaltClient, varPassword)) { if(varEncrypt){ //Decrypt varServerSocket << encrypt(varData); } else { //Encrypt varServerSocket << decrypt(varData); } } //varServerSocket << "Scope: " << varScope << " - Hash: " << varHash << " - Sent: " << varSaltServer << " - Recieved: " << varSaltClient << " - Password: "******"Verification Failed" << "\n\n"; } } catch ( SocketException& ) {} } } catch ( SocketException& e ) { std::cout << "An exception was caught:" << e.description() << "\nExiting.\n"; } return 0; }
void generateRandomSequence(const std::string & sequenceFile, size_t length) { std::ofstream fout(sequenceFile.c_str()); fout << ">BK0000000 TPA_inf: Random Sequence, " << length << "bp, complete sequence" << std::endl; fout << generateRandomString(length); fout.close(); }
Sample(){ int sz = rand() % 3 + 1; for (int i = 0; i < sz; ++i) randomStrings.push_back(generateRandomString(rand() % 5 +1)); }