diff options
Diffstat (limited to 'main.cpp')
-rw-r--r-- | main.cpp | 34 |
1 files changed, 23 insertions, 11 deletions
@@ -8,6 +8,7 @@ #include <cassert> #include "bigint.h" #include "numalgo.h" +#include "primes.h" #include "rsa.h" using namespace std; @@ -108,6 +109,23 @@ void repl(int argc,char **argv){ } } +void testisqrt(int argc,char **argv){ + int randsize=argc==2?strtol(argv[1],nullptr,10):1; + assert(randsize>=1); + for(int i=0;i<1000;i++){ + Bigint n(rand64()); + for(int j=1;j<randsize;j++){ + n<<=63; + n+=rand64(); + } + // cout<<hex<<n<<dec<<endl; + Bigint root(isqrt(n)); + assert(root*root<=n); + root+=Bigint::one; + assert(root*root>n); + } +} + void performrsa(){ PrivateKey privkey; Bigint p(1000000007),q(3000000019); @@ -115,8 +133,7 @@ void performrsa(){ privkey.pub.exp=65537; { Bigint x; - Bigint one(1); - egcd((p-one)*(q-one),privkey.pub.exp,x,privkey.pexp); + egcd((p-Bigint::one)*(q-Bigint::one),privkey.pub.exp,x,privkey.pexp); } cout<<"d = "<<privkey.pexp<<endl; Bigint msg(123456789); @@ -127,15 +144,10 @@ void performrsa(){ cout<<"msg = "<<msg2<<endl; } -int main(int,char**){ +int main(int argc,char **argv){ // biginttest(); // repl(argc,argv); - performrsa(); - // cout<<Bigint(0)-Bigint(69255535LL)<<endl; - // cout<<Bigint(0)-Bigint(669255535LL)<<endl; - // cout<<Bigint(0)-Bigint(5669255535LL)<<endl; - // cout<<Bigint(0)-Bigint(75669255535LL)<<endl; - // cout<<Bigint(0)-Bigint(775669255535LL)<<endl; - // cout<<Bigint(0)-Bigint(5775669255535LL)<<endl; - // cout<<Bigint(0)-Bigint(45775669255535LL)<<endl; + // performrsa(); + // testisqrt(argc,argv); + fillsmallprimes(); } |