void Operator::DumpOperator2File(string filename) { #ifdef OUTPUT_IN_DRAWINGUNITS double discLines_scaling = 1; #else double discLines_scaling = GetGridDelta(); #endif cout << "Operator: Dumping FDTD operator information to vtk file: " << filename << " ..." << flush; FDTD_FLOAT**** exc = Create_N_3DArray<FDTD_FLOAT>(numLines); if (Exc) { for (unsigned int n=0; n<Exc->Volt_Count; ++n) exc[Exc->Volt_dir[n]][Exc->Volt_index[0][n]][Exc->Volt_index[1][n]][Exc->Volt_index[2][n]] = Exc->Volt_amp[n]; } FDTD_FLOAT**** vv_temp = Create_N_3DArray<FDTD_FLOAT>(numLines); FDTD_FLOAT**** vi_temp = Create_N_3DArray<FDTD_FLOAT>(numLines); FDTD_FLOAT**** iv_temp = Create_N_3DArray<FDTD_FLOAT>(numLines); FDTD_FLOAT**** ii_temp = Create_N_3DArray<FDTD_FLOAT>(numLines); unsigned int pos[3], n; for (n=0; n<3; n++) for (pos[0]=0; pos[0]<numLines[0]; pos[0]++) for (pos[1]=0; pos[1]<numLines[1]; pos[1]++) for (pos[2]=0; pos[2]<numLines[2]; pos[2]++) { vv_temp[n][pos[0]][pos[1]][pos[2]] = GetVV(n,pos); vi_temp[n][pos[0]][pos[1]][pos[2]] = GetVI(n,pos); iv_temp[n][pos[0]][pos[1]][pos[2]] = GetIV(n,pos); ii_temp[n][pos[0]][pos[1]][pos[2]] = GetII(n,pos); } VTK_File_Writer* vtk_Writer = new VTK_File_Writer(filename.c_str(), m_MeshType); vtk_Writer->SetMeshLines(discLines,numLines,discLines_scaling); vtk_Writer->SetHeader("openEMS - Operator dump"); vtk_Writer->SetNativeDump(true); vtk_Writer->AddVectorField("vv",vv_temp); Delete_N_3DArray(vv_temp,numLines); vtk_Writer->AddVectorField("vi",vi_temp); Delete_N_3DArray(vi_temp,numLines); vtk_Writer->AddVectorField("iv",iv_temp); Delete_N_3DArray(iv_temp,numLines); vtk_Writer->AddVectorField("ii",ii_temp); Delete_N_3DArray(ii_temp,numLines); vtk_Writer->AddVectorField("exc",exc); Delete_N_3DArray(exc,numLines); if (vtk_Writer->Write()==false) cerr << "Operator::DumpOperator2File: Error: Can't write file... skipping!" << endl; cout << " done!" << endl; }
bool Decrypt(const wxString &sText, wxString &sDecryptText) { GByte *pabyKey = GetKey(); GByte *pabyIV = GetIV(); EVP_CIPHER_CTX* ctx = CreateCTX(pabyKey, pabyIV, true); if(!ctx) { wxLogError(_("Decrypt: Failed EVP_DecryptInit!")); CPLFree( pabyKey ); CPLFree( pabyIV ); return false; } int nTextBytes; GByte *pabyText = CPLHexToBinary( sText.mb_str(wxConvUTF8), &nTextBytes ); int outlen; unsigned char outbuf[BUFSIZE]; bool bResult = EVP_DecryptUpdate(ctx, outbuf, &outlen, pabyText, nTextBytes); if(!bResult) { wxLogError(_("Decrypt: Failed EVP_DecryptUpdate!")); CPLFree( pabyKey ); CPLFree( pabyIV ); CPLFree( pabyText ); return bResult; } int nLen = outlen; bResult = EVP_DecryptFinal(ctx, &outbuf[outlen], &outlen); nLen += outlen; outbuf[nLen] = 0; CPLString szCryptText((const char*)outbuf); sDecryptText = wxString(szCryptText, wxConvUTF8); CPLFree( pabyKey ); CPLFree( pabyIV ); CPLFree( pabyText ); EVP_CIPHER_CTX_cleanup(ctx); //EVP_CIPHER_CTX_free(ctx); return bResult; }
bool Crypt(const wxString &sText, wxString &sCryptText) { GByte *pabyKey = GetKey(); GByte *pabyIV = GetIV(); EVP_CIPHER_CTX* ctx = CreateCTX(pabyKey, pabyIV, false); if(!ctx) { wxLogError(_("Crypt: Failed EVP_EncryptInit!")); CPLFree( pabyKey ); CPLFree( pabyIV ); return false; } CPLString pszText(sText.mb_str(wxConvUTF8)); int outlen; unsigned char outbuf[BUFSIZE]; bool bResult = EVP_EncryptUpdate(ctx, outbuf, &outlen, (const unsigned char*)pszText.data(), pszText.length() * sizeof(pszText[0]) + 1); if(!bResult) { wxLogError(_("Crypt: Failed EVP_EncryptUpdate!")); CPLFree( pabyKey ); CPLFree( pabyIV ); return bResult; } int nLen = outlen; bResult = EVP_EncryptFinal(ctx, &outbuf[outlen], &outlen); nLen += outlen; CPLString pszOutput(CPLBinaryToHex(nLen, outbuf)); sCryptText = wxString(pszOutput, wxConvUTF8); CPLFree( pabyKey ); CPLFree( pabyIV ); EVP_CIPHER_CTX_cleanup(ctx); //EVP_CIPHER_CTX_free(ctx); return bResult; }
void *ThreadMain(void *clsk){ pthread_detach(pthread_self()); bool loggedon=false; char buffer[BUFFERSIZE]; std::string username, password, iv, key; //std::string* nameptr=&username; //pthread_detach(pthread_self()); int client_socket=*((int*)clsk); if(debugmode) std::cout<<"Successful thread, listening to client: "<<*((int*)clsk)<<std::endl; bool listening=true; while(listening){ if(debugmode) std::cout<<"Recieving input"<<std::endl; memset(buffer,0,BUFFERSIZE); read(client_socket, buffer, BUFFERSIZE); if(debugmode) std::cout<<"Successfully received message"<<std::endl; std::string input(buffer); if(debugmode) std::cout<<"decrypting input..."<<std::endl; //input=DecryptInput(input); //waiting for mario's code. if(debugmode) std::cout<<"converting message type"<<std::endl; messagetype action=ParseData(input); std::string receiver; std::string message; std::string confirmation; switch(action){ case LOGIN: //add validation code username=GetUserName(input); password=GetUserPassword(input); LogUserOn(username, &client_socket); //*nameptr=LogUserOn(input, &client_socket); SendMessage(username, username,t); iv=GetIV(username, password); SendMessage(username, username,iv); key=GetKey(username, password); SendMessage(username, username,key); if(debugmode) std::cout<<username<<std::endl; //std::cout<<*nameptr<<std::endl; loggedon=true; break; case LOGOFF: //add validation code // std::cout<<"checking for "<<*nameptr<<std::endl; if(debugmode) std::cout<<IsUserOnline(username)<<std::endl; // username=LogUserOn(input, &client_socket); if(debugmode) std::cout<<"checking for "<<username<<std::endl; // std::cout<<IsUserOnline(username)<<std::endl; LogUserOff(username); if(debugmode) std::cout<<IsUserOnline(username)<<std::endl; close(client_socket); loggedon=false; listening=false; break; case SENDMESSAGE: //add validation code receiver=GetMessageReceiver(input); message=GetMessage(input); message=FormatOutGoingMessage(username, message); SendMessage(username, receiver,message); break; case ADDUSER: //add validation code username=GetMessageReceiver(input); IsUserInDatabase(username); AddUserToDatabase(username); break; case CHANGEPASSWORD: IsUserInDatabase(username); break; case INVALID: //std::string invalid="invalid command"; //SendMessage(username, break; default: break; } } //zombie_threads++; pthread_exit(0); }