QByteArray Authentication::generateTemporaryPassword() const { static std::random_device rd; static std::mt19937 mt(rd()); static std::uniform_int_distribution<unsigned char> dist(0, 0xFF); auto temporary_password_length = 25; QByteArray tmp_p(temporary_password_length, 0); auto size = tmp_p.size(); for (int i = 0; i < size; i++){ tmp_p[i] = dist(mt); } return tmp_p; }
bool MultiSmoothSuperellipsoidIC::checkExtremes(unsigned int i, unsigned int j) { Point tmp_p; for (unsigned int pc = 0; pc < 6; pc++) { tmp_p = _centers[j]; // Find extremes along semiaxis of candidate ellipsoids if (pc == 0) tmp_p(0) -= _as[j]; else if (pc == 1) tmp_p(0) += _as[j]; else if (pc == 2) tmp_p(1) -= _bs[j]; else if (pc == 3) tmp_p(1) += _bs[j]; else if (pc == 4) tmp_p(2) -= _cs[j]; else tmp_p(2) += _cs[j]; const Point dist_vec = _mesh.minPeriodicVector(_var.number(), _centers[i], tmp_p); const Real dist = dist_vec.norm(); // Handle this case independently because we cannot calculate polar angles at this point if (MooseUtils::absoluteFuzzyEqual(dist, 0.0)) return true; // calculate rmn = r^(-n), replacing sin, cos functions with distances Real rmn = (std::pow(std::abs(dist_vec(0) / dist / _as[i]), _ns[i]) + std::pow(std::abs(dist_vec(1) / dist / _bs[i]), _ns[i]) + std::pow(std::abs(dist_vec(2) / dist / _cs[i]), _ns[i])); Real r = std::pow(rmn, (-1.0 / _ns[i])); if (dist < r) return true; } return false; }
/************** Each round consists of the following: 1. c1.multiplyBy(c0) 2. c0 += random constant 3. c2 *= random constant 4. tmp = c1 5. ea.rotate(tmp, random amount in [-nSlots/2, nSlots/2]) 6. c2 += tmp 7. ea.rotate(c2, random amount in [1-nSlots, nSlots-1]) 8. c1.negate() 9. c3.multiplyBy(c2) 10. c0 -= c3 **************/ void testGeneralOps(const FHEPubKey& publicKey, const FHESecKey& secretKey, const EncryptedArrayCx& ea, double epsilon, long nRounds) { long nslots = ea.size(); char buffer[32]; vector<cx_double> p0, p1, p2, p3; ea.random(p0); ea.random(p1); ea.random(p2); ea.random(p3); Ctxt c0(publicKey), c1(publicKey), c2(publicKey), c3(publicKey); ea.encrypt(c0, publicKey, p0, /*size=*/1.0); ea.encrypt(c1, publicKey, p1, /*size=*/1.0); ea.encrypt(c2, publicKey, p2, /*size=*/1.0); ea.encrypt(c3, publicKey, p3, /*size=*/1.0); resetAllTimers(); FHE_NTIMER_START(Circuit); for (long i = 0; i < nRounds; i++) { if (verbose) std::cout << "*** round " << i << "..."<<endl; long shamt = RandomBnd(2*(nslots/2) + 1) - (nslots/2); // random number in [-nslots/2..nslots/2] long rotamt = RandomBnd(2*nslots - 1) - (nslots - 1); // random number in [-(nslots-1)..nslots-1] // two random constants vector<cx_double> const1, const2; ea.random(const1); ea.random(const2); ZZX const1_poly, const2_poly; ea.encode(const1_poly, const1, /*size=*/1.0); ea.encode(const2_poly, const2, /*size=*/1.0); mul(p1, p0); // c1.multiplyBy(c0) c1.multiplyBy(c0); if (verbose) { CheckCtxt(c1, "c1*=c0"); debugCompare(ea, secretKey, p1, c1, epsilon); } add(p0, const1); // c0 += random constant c0.addConstant(const1_poly); if (verbose) { CheckCtxt(c0, "c0+=k1"); debugCompare(ea, secretKey, p0, c0, epsilon); } mul(p2, const2); // c2 *= random constant c2.multByConstant(const2_poly); if (verbose) { CheckCtxt(c2, "c2*=k2"); debugCompare(ea, secretKey, p2, c2, epsilon); } vector<cx_double> tmp_p(p1); // tmp = c1 Ctxt tmp(c1); sprintf(buffer, "tmp=c1>>=%d", (int)shamt); rotate(tmp_p, shamt); // ea.shift(tmp, random amount in [-nSlots/2,nSlots/2]) ea.rotate(tmp, shamt); if (verbose) { CheckCtxt(tmp, buffer); debugCompare(ea, secretKey, tmp_p, tmp, epsilon); } add(p2, tmp_p); // c2 += tmp c2 += tmp; if (verbose) { CheckCtxt(c2, "c2+=tmp"); debugCompare(ea, secretKey, p2, c2, epsilon); } sprintf(buffer, "c2>>>=%d", (int)rotamt); rotate(p2, rotamt); // ea.rotate(c2, random amount in [1-nSlots, nSlots-1]) ea.rotate(c2, rotamt); if (verbose) { CheckCtxt(c2, buffer); debugCompare(ea, secretKey, p2, c2, epsilon); } negateVec(p1); // c1.negate() c1.negate(); if (verbose) { CheckCtxt(c1, "c1=-c1"); debugCompare(ea, secretKey, p1, c1, epsilon); } mul(p3, p2); // c3.multiplyBy(c2) c3.multiplyBy(c2); if (verbose) { CheckCtxt(c3, "c3*=c2"); debugCompare(ea, secretKey, p3, c3, epsilon); } sub(p0, p3); // c0 -= c3 c0 -= c3; if (verbose) { CheckCtxt(c0, "c0=-c3"); debugCompare(ea, secretKey, p0, c0, epsilon); } } c0.cleanUp(); c1.cleanUp(); c2.cleanUp(); c3.cleanUp(); FHE_NTIMER_STOP(Circuit); vector<cx_double> pp0, pp1, pp2, pp3; ea.decrypt(c0, secretKey, pp0); ea.decrypt(c1, secretKey, pp1); ea.decrypt(c2, secretKey, pp2); ea.decrypt(c3, secretKey, pp3); std::cout << "Test "<<nRounds<<" rounds of mixed operations, "; if (cx_equals(pp0, p0,conv<double>(epsilon*c0.getPtxtMag())) && cx_equals(pp1, p1,conv<double>(epsilon*c1.getPtxtMag())) && cx_equals(pp2, p2,conv<double>(epsilon*c2.getPtxtMag())) && cx_equals(pp3, p3,conv<double>(epsilon*c3.getPtxtMag()))) std::cout << "PASS\n\n"; else { std::cout << "FAIL:\n"; std::cout << " max(p0)="<<largestCoeff(p0) << ", max(pp0)="<<largestCoeff(pp0) << ", maxDiff="<<calcMaxDiff(p0,pp0) << endl; std::cout << " max(p1)="<<largestCoeff(p1) << ", max(pp1)="<<largestCoeff(pp1) << ", maxDiff="<<calcMaxDiff(p1,pp1) << endl; std::cout << " max(p2)="<<largestCoeff(p2) << ", max(pp2)="<<largestCoeff(pp2) << ", maxDiff="<<calcMaxDiff(p2,pp2) << endl; std::cout << " max(p3)="<<largestCoeff(p3) << ", max(pp3)="<<largestCoeff(pp3) << ", maxDiff="<<calcMaxDiff(p3,pp3) << endl<<endl; } if (verbose) { std::cout << endl; printAllTimers(); std::cout << endl; } resetAllTimers(); }
OP_ERROR SOP_Ocean::cookMySop(OP_Context &context) { float now = context.getTime(); //std::cout << "cook ocean, t = " << now << std::endl; // lock inputs if (lockInputs(context) >= UT_ERROR_ABORT ) { return error(); } GEO_Point *ppt; UT_Interrupt *boss; // Check to see that there hasn't been a critical error in cooking the SOP. if (error() < UT_ERROR_ABORT) { boss = UTgetInterrupt(); // Start the interrupt server boss->opStart("Updating Ocean"); duplicatePointSource(0,context); int gridres = 1 << int(GRID_RES(now)); float stepsize = GRID_SIZE(now) / (float)gridres; bool do_chop = CHOP(now); bool do_jacobian = JACOBIAN(now); bool do_normals = NORMALS(now) && !do_chop; if (!_ocean || _ocean_needs_rebuild) { if (_ocean) { delete _ocean; } if (_ocean_context) { delete _ocean_context; } _ocean = new drw::Ocean(gridres,gridres,stepsize,stepsize, V(0),L(0),1.0,W(0),1-DAMP(0),ALIGN(0), DEPTH(0),SEED(0)); _ocean_scale = _ocean->get_height_normalize_factor(); _ocean_context = _ocean->new_context(true,do_chop,do_normals,do_jacobian); _ocean_needs_rebuild = false; // std::cout << "######### SOP, rebuilt ocean, norm_factor = " << _ocean_scale // << " chop = " << do_chop // << " norm = " << do_normals // << " jacobian = " << do_jacobian // << std::endl; } float chop_amount = CHOPAMOUNT(now); // sum up the waves at this timestep _ocean->update(TIME(now),*_ocean_context,true,do_chop,do_normals,do_jacobian, _ocean_scale * SCALE(now),chop_amount); bool linterp = ! INTERP(now); // get our attribute indices GA_RWAttributeRef normal_index; GA_RWAttributeRef jminus_index; GA_RWAttributeRef eminus_index; if (do_normals) { normal_index = gdp->addNormalAttribute(GEO_POINT_DICT); } if (do_jacobian) { // jminus_index = gdp->addPointAttrib("mineigval",sizeof(float),GB_ATTRIB_FLOAT,0); // eminus_index = gdp->addPointAttrib("mineigvec",sizeof(UT_Vector3),GB_ATTRIB_VECTOR,0); jminus_index = gdp->addTuple(GA_STORE_REAL32,GA_ATTRIB_POINT,"mineigval",1,GA_Defaults(0)); eminus_index = gdp->addFloatTuple(GA_ATTRIB_POINT,"mineigvec",1,GA_Defaults(0)); } // this is not that fast, can it be done quicker ??? GA_FOR_ALL_GPOINTS(gdp, ppt) { UT_Vector4 p = ppt->getPos(); if (linterp) { _ocean_context->eval_xz(p(0),p(2)); } else { _ocean_context->eval2_xz(p(0),p(2)); } if (do_chop) { p.assign( p(0) + _ocean_context->disp[0], p(1) + _ocean_context->disp[1], p(2) + _ocean_context->disp[2] ); } else { // ppt->getPos()(1) += _ocean_context->disp[1]; UT_Vector4 tmp_p = ppt->getPos(); tmp_p(1) += _ocean_context->disp[1]; ppt->setPos(tmp_p); } if (do_normals) { /* UT_Vector3* normal = (UT_Vector3*) ppt->castAttribData<UT_Vector3>(normal_index); normal->assign(_ocean_context->normal[0], _ocean_context->normal[1], _ocean_context->normal[2]); normal->normalize(); */ ppt->getValue<UT_Vector3>(normal_index).assign(_ocean_context->normal[0], _ocean_context->normal[1], _ocean_context->normal[2]); ppt->getValue<UT_Vector3>(normal_index).normalize(); } if (do_jacobian) {/* float *js = (float*)ppt->castAttribData<float>(jminus_index); *js = _ocean_context->Jminus; UT_Vector3* eminus = (UT_Vector3*)ppt->castAttribData<UT_Vector3>(eminus_index); eminus->assign(_ocean_context->Eminus[0],0,_ocean_context->Eminus[1]); */ ppt->setValue<float>(jminus_index,_ocean_context->Jminus); ppt->getValue<UT_Vector3>(eminus_index).assign(_ocean_context->Eminus[0],0,_ocean_context->Eminus[1]); } ppt->setPos(p); }