#include "socketio.hpp" #include "crypt/BigInt64.hpp" #include #include #include #include #include xoshiro_256 gen(42); unsigned long long nanoTime(){ using namespace std; using namespace std::chrono; return duration_cast(high_resolution_clock::now().time_since_epoch()).count(); } template std::ostream& operator<<(std::ostream& out, std::vector o){ out << "["; for(unsigned int i = 0;i < o.size();i++){ if(o[i] == '\r')continue; out << o[i]; if(i < o.size() - 1) out << ", "; } return out << "]"; } template<> std::ostream& operator<< (std::ostream& out, std::vector o){ for(unsigned int i = 0;i < o.size();i++){ out << o[i]; } return out; } unsigned long long multTest(size_t s){ BigInt a(gen,s); BigInt b(gen,s); std::vector times(0); for(int o = 0;o < 4;o++){ auto t1 = nanoTime(); for(int i = 0;i < 1000;i++){ a = a.mult(b); a.cut(s); } auto t2 = nanoTime(); times.push_back((t2 - t1)); } std::sort(times.begin(), times.end()); /*for(auto t : times){ std::cout << t/1000 << ", "; }*/ //std::cout << std::endl; return std::accumulate(times.begin(), times.end(), 0ULL); } int mailn(){ BigInt a("4528437659827"); BigInt b(gen, 31); BigInt res = a.modPow(b, secure_prime); std::cout << res.toString() << std::endl; //return 0; multTest(50); //multTest(100); //multTest(200); std::cout << multTest(50 ) / 1000 / 1000 << " ms" << std::endl; std::cout << multTest(100) / 1000 / 1000 << " ms" << std::endl; std::cout << multTest(200) / 1000 / 1000 << " ms" << std::endl; std::cout << multTest(400) / 1000 / 1000 << " ms" << std::endl; //std::cout << multTest(800) / 1000 / 1000 << " ms" << std::endl; } int main(){ cppsocket sock("127.0.0.1", 80); //cppsocket sock("127.0.0.1", 80); std::vector toSend(10); for(unsigned int i = 0;i < toSend.size();i++){ toSend[i] = (char)(i * i) % 10 + 'a'; } //std::cout << errno << std::endl; try{ for(int i = 0;i < 100;i++){ sock.write(toSend); std::cout << "Rec" << std::endl; std::cout << sock.receive() << std::endl; //std::this_thread::sleep_for(std::chrono::milliseconds(1)); } } catch(std::exception& e){ std::cout << e.what() << std::endl; } //std::cout << "Sent " << std::to_string(toSend.size()) << ", Receiving..." << std::endl; //sock.write(std::vector(1,1)); //std::vector vec = sock.receive(); //std::cout << (vec == toSend); //std::cout << vec << std::endl; //vec = sock.receive(); //std::cout << vec << std::endl; return 0; }