int main() { int x, r, a, b, c, h; cout<<"x=1 pole kola"<<endl; cout<<"x=2 pole prostopadloscianu"<<endl; cout<<"x=3 pole trojkata"<<endl; cout<<"Wybieraj x"<<endl; cin>>x; switch (x) { case 1: { cout<<"Pole kola: "<<pk(r)<<endl; break; } case 2: { cout<<"Pole prostopadloscianu: "<<pp(a,b,c)<<endl; break;} case 3: { cout<<"Pole trojkata: "<<pt(a,h)<<endl; break;} default: {cout<<"Nie ma takiej cyfry"<<endl;} } system("pause"); }
int main(void) { int pair[2]; if (pipe(pair) != 0) return -1; // run server thread Server srv(pair[0]); pthread_t thread; pthread_create(&thread, NULL, run_server, reinterpret_cast<void*>(&srv)); // client thread: fwriter writer(pair[1]); msgpack::packer<fwriter> pk(writer); typedef msgpack::type::tuple<std::string, std::string, std::string> put_t; typedef msgpack::type::tuple<std::string, std::string> get_t; put_t req1("put", "apple", "red"); put_t req2("put", "lemon", "yellow"); get_t req3("get", "apple"); pk.pack(req1); pk.pack(req2); pk.pack(req3); writer.flush(); writer.close(); pthread_join(thread, NULL); }
int cServer::Init(short a_ListenPort, short a_ConnectPort) { m_ConnectPort = a_ConnectPort; WSAData wsa; int res = WSAStartup(0x0202, &wsa); if (res != 0) { printf("Cannot initialize WinSock: %d\n", res); return res; } printf("Generating protocol encryption keypair...\n"); time_t CurTime = time(NULL); RandomPool rng; rng.Put((const byte *)&CurTime, sizeof(CurTime)); m_PrivateKey.GenerateRandomWithKeySize(rng, 1024); RSA::PublicKey pk(m_PrivateKey); m_PublicKey = pk; m_ListenSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); sockaddr_in local; memset(&local, 0, sizeof(local)); local.sin_family = AF_INET; local.sin_addr.s_addr = 0; // All interfaces local.sin_port = htons(a_ListenPort); bind(m_ListenSocket, (sockaddr *)&local, sizeof(local)); listen(m_ListenSocket, 1); printf("Listening on port %d, connecting to localhost:%d\n", a_ListenPort, a_ConnectPort); return 0; }
void initIndex::writeTitleListToIndexFile() { msgpack::sbuffer buffer; msgpack::packer<msgpack::sbuffer> pk(&buffer); pk.pack_array(TitleList.size()); for (const auto &i : TitleList) { pk.pack_array(2); pk.pack(i.first); pk.pack_array(2); pk.pack(i.second.first); pk.pack(i.second.second); } unsigned int _size = (buffer.size() / 4096 + 1) * 4096; titleListManifest.push_back(_size); HANDLE nIndFile = CreateFile(TEXT("data\\title.ind"), GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); DWORD dwNB; LARGE_INTEGER li = { 0 }; SetFilePointerEx(nIndFile, li, NULL, FILE_END); WriteFile(nIndFile, buffer.data(), _size, &dwNB, NULL); CloseHandle(nIndFile); TitleList.clear(); }
JNIEXPORT void JNICALL Java_JaCl_printTest(JNIEnv *env, jobject obj, jlong ptr, jstring j_pk) { NaClInterface* nacl_interface = reinterpret_cast<NaClInterface*>(ptr); std::cout << "C++ side public_key: " << nacl_interface->public_key() << " length: " << nacl_interface->public_key().length() << "\n"; std::string pk((const char*)env->GetStringChars(j_pk, 0), (size_t)env->GetStringLength(j_pk)); std::cout << "C++ side passed public_key: " << pk << " length: " << pk.length() << "\n"; }
void processMouseButton(int button, int state, int x, int y) { PhysicalKey pk(button, MOUSE_BUTTON); if(state == GLUT_DOWN) Input::updateKeyDown(pk); if(state == GLUT_UP) Input::updateKeyUp(pk); }
static jobject NewPurchaseManagerObject(string pubkey) { if (!jni->purchases_class) jni->purchases_class = CheckNotNull (jclass(jni->env->NewGlobalRef(jni->env->FindClass("com/lucidfusionlabs/billing/PurchaseManager")))); static jmethodID mid = CheckNotNull (jni->env->GetStaticMethodID(jni->purchases_class, "createStaticInstance", "(Lcom/lucidfusionlabs/core/LifecycleActivity;Ljava/lang/String;)Lcom/lucidfusionlabs/billing/PurchaseManager;")); LocalJNIString pk(jni->env, JNI::ToJString(jni->env, pubkey)); return jni->env->CallStaticObjectMethod(jni->purchases_class, mid, jni->activity, pk.v); }
int DirectPackerImpl::packArray(lua_State* L, int arg_base) { sbuffer buffer; packer<sbuffer> pk(&buffer); LuaObjects obj(L, arg_base); obj.packArray(pk); lua_pushlstring(L, buffer.data(), buffer.size()); return 1; }
bool verify_rsa(bytes_t *doc, bytes_t *signature, const key_metainfo_t *metainfo) { const public_key_t *tc_pk = tc_key_meta_info_public_key(metainfo); Botan::BigInt n((Botan::byte *) tc_pk->n->data, tc_pk->n->data_len); Botan::BigInt e((Botan::byte *) tc_pk->e->data, tc_pk->e->data_len); Botan::RSA_PublicKey pk(n, e); Botan::PK_Verifier verifier(pk, "EMSA4(SHA-256)"); verifier.update((Botan::byte*) doc->data, doc->data_len); return verifier.check_signature((Botan::byte*)signature->data, signature->data_len); }
void registrationKeyDialog::sSelect() { XTupleProductKey pk(_key->text().trimmed()); if (pk.valid()) { _metrics->set("RegistrationKey", _key->text().trimmed()); _metrics->set("NewRegistrationKeyRequested", QString()); accept(); } }
void PeerDiscovery::DomainPeerDiscovery::messages_reload() { sbuf_.clear(); msgpack::packer<msgpack::sbuffer> pk(&sbuf_); pk.pack_map(messages_.size()); for (const auto& m : messages_) { pk.pack(m.first); sbuf_.write(m.second.data(), m.second.size()); } }
double update(std::string key, std::string delta, update_result update_func){ std::string val; double v = 3.21; paracel::packer<double> pk(v); pk.pack(val); std::string new_val = update_func(val, delta); paracel::packer<double> pk2; return pk2.unpack(new_val); }
bool TileMap::is_cell_y_flipped(int p_x,int p_y) const { PosKey pk(p_x,p_y); const Map<PosKey,Cell>::Element *E=tile_map.find(pk); if (!E) return false; return E->get().flip_v; }
double RealModel::GetParam(int n) { assert(0 <= n && n < Nbands); const int Nk = 256; double k, kmin = bands[n].min, kmax = bands[n].max; /* Compute average value of P(k) over the interval [kmin,kmax], i.e. a "band power" */ double sum = 0; for(int i = 0; i < Nk; i++) { k = kmin + (i + 0.5)*(kmax - kmin)/Nk; sum += pk(k); } return sum/Nk; }
void registrationKeyDialog::sSelect() { XTupleProductKey pk(_key->text()); if(pk.valid()) { XSqlQuery keyq; keyq.prepare("UPDATE metric SET metric_value=:key WHERE metric_name='RegistrationKey';"); keyq.bindValue(":key", _key->text()); keyq.exec(); } done(0); }
void act_server(int socket) { FHEcontext context(gM, gP, gR); buildModChain(context, gL); FHEPubKey pk(context); receive_pk(socket, pk); std::vector<Ctxt> ctxts(gC, pk); for (long i = 0; i < gC; i++) pk.Encrypt(ctxts[i], NTL::to_ZZX(i)); send_ctxts(socket, ctxts); nn_close(socket); }
bool MsgpackTester::SerializeData(const TestData& t, void* data, uint32_t& size) { msgpack::sbuffer buffer; msgpack::packer<msgpack::sbuffer> pk(&buffer); const MsgpackTestData& pt = dynamic_cast<const MsgpackTestData&>(t); for (uint32_t i = 0; i < pt.num_; ++i) { pk.pack(pt.objs_[i]); } size = buffer.size(); memcpy(data, buffer.data(), size); return true; }
int TileMap::get_cell(int p_x,int p_y) const { PosKey pk(p_x,p_y); const Map<PosKey,Cell>::Element *E=tile_map.find(pk); if (!E) return INVALID_CELL; return E->get().id; }
void TileMap::set_cell(int p_x,int p_y,int p_tile,bool p_flip_x,bool p_flip_y,bool p_transpose) { PosKey pk(p_x,p_y); Map<PosKey,Cell>::Element *E=tile_map.find(pk); if (!E && p_tile==INVALID_CELL) return; //nothing to do PosKey qk(p_x/_get_quadrant_size(),p_y/_get_quadrant_size()); if (p_tile==INVALID_CELL) { //erase existing tile_map.erase(pk); Map<PosKey,Quadrant>::Element *Q = quadrant_map.find(qk); ERR_FAIL_COND(!Q); Quadrant &q=Q->get(); q.cells.erase(pk); if (q.cells.size()==0) _erase_quadrant(Q); else _make_quadrant_dirty(Q); return; } Map<PosKey,Quadrant>::Element *Q = quadrant_map.find(qk); if (!E) { E=tile_map.insert(pk,Cell()); if (!Q) { Q=_create_quadrant(qk); } Quadrant &q=Q->get(); q.cells.insert(pk); } else { ERR_FAIL_COND(!Q); // quadrant should exist... if (E->get().id==p_tile && E->get().flip_h==p_flip_x && E->get().flip_v==p_flip_y && E->get().transpose==p_transpose) return; //nothing changed } Cell &c = E->get(); c.id=p_tile; c.flip_h=p_flip_x; c.flip_v=p_flip_y; c.transpose=p_transpose; _make_quadrant_dirty(Q); }
TEST(streaming, basic_pointer) { msgpack::sbuffer buffer; msgpack::packer<msgpack::sbuffer> pk(&buffer); pk.pack(1); pk.pack(2); pk.pack(3); const char* input = buffer.data(); const char* const eof = input + buffer.size(); msgpack::unpacker pac; msgpack::object_handle oh; int count = 0; while(count < 3) { pac.reserve_buffer(32*1024); // read buffer into pac.buffer() upto // pac.buffer_capacity() bytes. size_t len = 1; memcpy(pac.buffer(), input, len); input += len; pac.buffer_consumed(len); #if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2)) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wdeprecated-declarations" #endif // (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2)) while(pac.next(&oh)) { #if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2)) #pragma GCC diagnostic pop #endif // (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2)) msgpack::object obj = oh.get(); switch(count++) { case 0: EXPECT_EQ(1, obj.as<int>()); break; case 1: EXPECT_EQ(2, obj.as<int>()); break; case 2: EXPECT_EQ(3, obj.as<int>()); return; } } EXPECT_TRUE(input < eof); } }
void cServer::PrepareKeys(void) { // TODO: Save and load key for persistence across sessions // But generating the key takes only a moment, do we even need that? LOGD("Generating protocol encryption keypair..."); time_t CurTime = time(NULL); CryptoPP::RandomPool rng; rng.Put((const byte *)&CurTime, sizeof(CurTime)); m_PrivateKey.GenerateRandomWithKeySize(rng, 1024); CryptoPP::RSA::PublicKey pk(m_PrivateKey); m_PublicKey = pk; }
void registrationKeyDialog::sRequest() { QString urlstr("https://xtuple.com/request-new-license-key"); QUrl url(urlstr); XTupleProductKey pk(_key->text().trimmed()); if (! pk.customerId().isEmpty()) url.setQuery(QString("customerId=%1").arg(pk.customerId()), QUrl::StrictMode); _status->setHtml(tr("Opening %1").arg(urlstr)); QDesktopServices::openUrl(url); _metrics->set("NewRegistrationKeyRequested", tr("New key requested on %1").arg(QDate::currentDate().toString(Qt::ISODate))); }
/** * @brief Returns our public and private keys */ QPair<QByteArray, QByteArray> Core::getKeypair() const { QPair<QByteArray, QByteArray> keypair; if (!tox) { return keypair; } QByteArray pk(TOX_PUBLIC_KEY_SIZE, 0x00); QByteArray sk(TOX_SECRET_KEY_SIZE, 0x00); tox_self_get_public_key(tox, reinterpret_cast<uint8_t*>(pk.data())); tox_self_get_secret_key(tox, reinterpret_cast<uint8_t*>(sk.data())); keypair.first = pk; keypair.second = sk; return keypair; }
TEST(streaming, move) { msgpack::sbuffer buffer; msgpack::packer<msgpack::sbuffer> pk(&buffer); pk.pack(1); pk.pack(2); pk.pack(3); const char* input = buffer.data(); const char* const eof = input + buffer.size(); msgpack::unpacker pac; msgpack::object_handle oh; int count = 0; while(count < 3) { msgpack::unpacker pac_in(std::move(pac)); pac_in.reserve_buffer(32*1024); // read buffer into pac_in.buffer() upto // pac_in.buffer_capac_inity() bytes. size_t len = 1; memcpy(pac_in.buffer(), input, len); input += len; pac_in.buffer_consumed(len); while(pac_in.next(oh)) { msgpack::object obj = oh.get(); switch(count++) { case 0: EXPECT_EQ(1, obj.as<int>()); break; case 1: EXPECT_EQ(2, obj.as<int>()); break; case 2: EXPECT_EQ(3, obj.as<int>()); return; } } EXPECT_TRUE(input < eof); pac = std::move(pac_in); } }
ATOOLS::Vec4D_Vector Combine (const Cluster_Amplitude &l,int i,int j,int k,const ATOOLS::Flavour &mo) { Mass_Selector *p_ms=ampl.MS(); if (i>j) std::swap<int>(i,j); Vec4D_Vector after(ampl.Legs().size()-1); double mb2(0.0); if (i<2) { mb2=ampl.Leg(1-i)->Mom().Abs2(); double mfb2(p_ms->Mass2(ampl.Leg(1-i)->Flav())); if ((mfb2==0.0 && IsZero(mb2,1.0e-6)) || IsEqual(mb2,mfb2,1.0e-6)) mb2=mfb2; } Vec4D pi(ampl.Leg(i)->Mom()), pj(ampl.Leg(j)->Mom()); Vec4D pk(ampl.Leg(k)->Mom()), pb(i<2?ampl.Leg(1-i)->Mom():Vec4D()); double mi2=pi.Abs2(), mfi2=p_ms->Mass2(ampl.Leg(i)->Flav()); double mj2=pj.Abs2(), mfj2=p_ms->Mass2(ampl.Leg(j)->Flav()); double mk2=pk.Abs2(), mfk2=p_ms->Mass2(ampl.Leg(k)->Flav()); if ((mfi2==0.0 && IsZero(mi2,1.0e-6)) || IsEqual(mi2,mfi2,1.0e-6)) mi2=mfi2; if ((mfj2==0.0 && IsZero(mj2,1.0e-6)) || IsEqual(mj2,mfj2,1.0e-6)) mj2=mfj2; if ((mfk2==0.0 && IsZero(mk2,1.0e-6)) || IsEqual(mk2,mfk2,1.0e-6)) mk2=mfk2; double mij2=p_ms->Mass2(mo); Kin_Args lt; if (i>1) { if (k>1) lt=ClusterFFDipole(mi2,mj2,mij2,mk2,pi,pj,pk,2); else lt=ClusterFIDipole(mi2,mj2,mij2,mk2,pi,pj,-pk,2); if ((k==0 && lt.m_pk[3]<0.0) || (k==1 && lt.m_pk[3]>0.0) || lt.m_pk[0]<0.0) return Vec4D_Vector(); } else { if (k>1) { lt=ClusterIFDipole(mi2,mj2,mij2,mk2,mb2,-pi,pj,pk,-pb,2); } else lt=ClusterIIDipole(mi2,mj2,mij2,mk2,-pi,pj,-pk,2); if ((i==0 && lt.m_pi[3]<0.0) || (i==1 && lt.m_pi[3]>0.0) || lt.m_pi[0]<0.0) return Vec4D_Vector(); } if (lt.m_stat<0) return Vec4D_Vector(); for (size_t l(0), m(0);m<ampl.Legs().size();++m) { if (m==(size_t)j) continue; if (m==(size_t)i) after[l]=i>1?lt.m_pi:-lt.m_pi; else if (m==(size_t)k) after[l]=k>1?lt.m_pk:-lt.m_pk; else after[l]=lt.m_lam*ampl.Leg(m)->Mom(); ++l; } return after; }
int main(int argc, char** argv) { boost::asio::io_service ios; opmip::net::link::ethernet::socket sk(ios); opmip::net::link::ethernet::endpoint ep(opmip::net::link::ethernet::ipv6, 2, opmip::net::link::ethernet::endpoint::outgoing, opmip::ll::mac_address::from_string("00:11:22:33:44:55")); opmip::net::ip::icmp6_ra_packet ra; opmip::net::ip::ipv6_packet pk(opmip::ip::address_v6::from_string("fe80::1"), opmip::ip::address_v6::from_string("ff02::1"), 128, ra); sk.open(opmip::net::link::ethernet(0x0003)); sk.send_to(pk.cbuffer(), ep); }
void Core::onGroupInvite(Tox*, int32_t friendNumber, uint8_t type, const uint8_t *data, uint16_t length,void *core) { QByteArray pk((char*)data, length); if (type == TOX_GROUPCHAT_TYPE_TEXT) { qDebug() << QString("Text group invite by %1").arg(friendNumber); emit static_cast<Core*>(core)->groupInviteReceived(friendNumber,type,pk); } else if (type == TOX_GROUPCHAT_TYPE_AV) { qDebug() << QString("AV group invite by %1").arg(friendNumber); emit static_cast<Core*>(core)->groupInviteReceived(friendNumber,type,pk); } else { qWarning() << "Group invite with unknown type "<<type; } }
void main(){ int N, i; /*vector de trabajo y vector resultado*/ int p, k; srand(getpid()); /*generamos un p aleatorio srand(getpid()); la semilla será el Pid del proceso int p=(rand()%(LVECT-2))+1; rango de p: [1, x] , x es la longitud del vector -1 (k-ésimo elemento) generamos un k aleatorio int k=rand()%(LVECT-1); rango de k: [0, LVECT -1] */ printf("Introduzca un valor para N:\n"); scanf("%d", &N); int v[N]; p=N/2; printf("Introduzca un valor para K:\n"); scanf("%d", &k); int inf=k-p/2; int sup=k+(p-p/2); printf("\nVector de números aleatorios:\n"); for (i=0; i<N; i++){ v[i]=rand()%100; printf("%d\t", v[i]); } int copia[N]; for(i=0; i< N; i++) copia[i]=v[i]; printf("\nVector ordenado con QS:\n"); QS(copia, 0, N-1); printvec(copia, N); printf("\n\ninf: %d\nsup: %d\n", inf, sup); pk(v, p, inf, sup, k); printf("\n"); printvec(v, N); }
void bench_msgpack_str() { simple_buffer buf; simple_timer timer; std::cout << "----" << std::endl; std::cout << "pack string" << std::endl; timer.reset(); { msgpack::packer<simple_buffer> pk(buf); pk.pack_array(TASK_STR_LEN); for(unsigned int i=0; i < TASK_STR_LEN; ++i) { pk.pack_raw(i); pk.pack_raw_body(TASK_STR_PTR, i); } } timer.show_stat(buf.size()); std::cout << "----" << std::endl; std::cout << "unpack string" << std::endl; msgpack::zone z; msgpack::object obj; timer.reset(); { obj = msgpack::unpack(buf.data(), buf.size(), z); } timer.show_stat(buf.size()); /* std::cout << "----" << std::endl; std::cout << "dynamic pack string" << std::endl; buf.clear(); timer.reset(); msgpack::pack(buf, obj); timer.show_stat(buf.size()); */ }
TEST(streaming, event_compat) { std::stringstream stream; msgpack::packer<std::ostream> pk(&stream); event_handler_compat handler(stream); pk.pack(1); handler.expect = 1; handler.on_read(); pk.pack(2); handler.expect = 2; handler.on_read(); pk.pack(3); handler.expect = 3; handler.on_read(); }