#include #include #include #include #include #include #include #include #include "bigint.h" #include "numalgo.h" #include "primes.h" #include "rsa.h" using namespace std; class eof_error : public runtime_error{ public: eof_error() :runtime_error("EOF"){} }; int64_t rand64(){ return ((int64_t)rand()<<32)+(((int64_t)rand()%2)<<31)+rand(); } Bigint readevalexpr(istream &is){ Bigint a; is>>a; if(is.eof())throw eof_error(); // cerr<<"Read "<>s; assert(!is.fail()); a=readevalexpr(is); Bigint b=readevalexpr(is); //cerr<<"Operation "<>bi; assert(bi==Bigint(n)); } } #endif #if 1 { string s="4405994068155852661780322209877856931246944549396705884037139443014164958640201650440984581318995014"; istringstream iss(s); Bigint bi; iss>>bi; uint32_t digs[11]={1752788038,953502834,2175607868,1627159508,1754291416,1207689192,3196357285,3165170272,3313904421,3194703103,2062}; for(int i=0;i<11;i++)assert(bi._digit(i)==digs[i]); ostringstream oss; oss<=1); for(int i=0;i<1000;i++){ Bigint n(rand64()); for(int j=1;jn); } } void performrsa(){ PrivateKey privkey; Bigint p(1000000007),q(3000000019U); privkey.pub.mod=3000000040000000133LL; privkey.pub.exp=65537; { Bigint x; egcd((p-Bigint::one)*(q-Bigint::one),privkey.pub.exp,x,privkey.pexp); } cout<<"d = "<