std::string PhraseGenerator::getAlphNumericPhrase(int numChars) { stringstream ss; std::string str; int chars = 0; while (chars < numChars) { int upperOrLowerInt = rand() % MAX_DIGIT + 1; char ch; if (upperOrLowerInt % 2 == 0) { ss << getRandomChar(); chars++; } else { ss << getRandomDigit(); chars++; } } getline(ss, str); return str; }
int main(int argc, char **argv) { int tmp; int i; int j; int msgCnt = 0; clMsg myMsg; srand((uint)time(0)); if(argc != 2) myerror("Nieprawidłowa ilość argumentów! (Podaj jeden -- nazwę klienta)",1); myMsg.type = 72; strncpy(myMsg.myNameIs, argv[1], CLNAMELEN); myMsg.myNameIs[CLNAMELEN-1] = 0; myMsg.myCard = getpid(); signal(SIGINT, makeMeQuit); /*och proszę, niech będą te dwa polecenia atomowe...*/ tmp = atexit(myatexit); if(tmp != 0) { myatexit(); myerror("Błąd atexit()!",2); } KS_h = mq_open(KSNAME,O_WRONLY); if(KS_h == (mqd_t)-1) myerror("Błąd mq_open (KS)!",1); KK_h = mq_open(KKNAME,O_RDONLY); if(KK_h == (mqd_t)-1) { tmp = mq_close(KS_h); if(tmp == -1) fprintf(stderr,"Błąd zamknięcia kolejki KS! errno=%d\n",errno); myerror("Błąd mq_open (KK)!",3); } signal(SIGUSR1, sigSigSigSigSigSig); for(;;) { /*klientujemy*/ printf("Ile mesydżów wysłać? : "); scanf(" %d",&msgCnt); if(msgCnt < 0) { printf("\nBłąd -- podano ujemną liczbę!\n"); continue; } for(i=0;i<msgCnt;++i) { j = rand()%CLMSGLEN; myMsg.iWantToSay[j+1] = 0; for(; j >= 0; --j) myMsg.iWantToSay[j] = getRandomChar(); showClMsg(&myMsg,0); tmp = mq_send(KS_h, (char*)&myMsg, sizeof(clMsg), 0); if(tmp == -1) myerror("Błąd mq_send!",4); hr(); } } return 0; }
ClientObject* getClientInfoById(unsigned int ip_ident){ if(ip_ident>=registred_clients.size()){return NULL;} ClientObject* co = registred_clients[ip_ident]; if(co->state==CLIENT_STATE_REGISTRED){ co->lastActivityTime=time(NULL); return registred_clients[ip_ident]; } if(co->state==CLIENT_STATE_USED){return NULL;} if(co->state==CLIENT_STATE_WAIT_RESPONSE){return NULL;} if(co->state==CLIENT_STATE_UNUSED){ if(!devices.size()){return NULL;} co->state=CLIENT_STATE_WAIT_RESPONSE; randomize(); int it=18+(getRandomChar()%16); char cd[128]; sprintf(cd,"%x.ll",rand()%255); co->local_domain->append(cd); for(int i=0;i<it;i++){ unsigned char c=getRandomChar(); co->local_unique_identifier->append((char*)&c,1); } //generating chains printf("=================== \nNEW USER %s LOCAL IP: ",cd); print_ip4(co->local_addr); printf("\n"); for(int i=0;i<5;i++){ make_and_append_chain(co); } printf("=================== \n"); RSSObject* setChainRequest=new RSSObject(getDefinedStructs(),"setChainsRequest"); setChainRequest->objectByName("address")->setUintObjectByName("type",ADDR_TYPE_DOMAIN); setChainRequest->setUintObjectByName("encryption_method",RS_ENCRYPTION_BLOWFISH); setChainRequest->objectByName("address")->dynObjectByName("address")->append(co->local_domain->data(),co->local_domain->length()); setChainRequest->dynObjectByName("traffic_key")->append(co->traffic_key->data(),co->traffic_key->length()); setChainRequest->objectByName("chains")->assign(co->chains); rsock->sendToRouteServer(RS_CMD_SETCHAINS_REQUEST,setChainRequest); delete setChainRequest; return NULL; } return NULL; }
int main(void) { int l = 1; char scelta; do { printf("\nInsert Password length: "); scanf("%d",&l); srand((unsigned int) time(0) + getpid()); printf("\n"); for (;l>0;l--) { putchar(getRandomChar(rand())); srand(rand()); } printf("\n"); printf("Premi c per generarne un altra..."); scelta = getche(); } while(scelta=='c'); }