diff options
Diffstat (limited to 'rsa.cpp')
-rw-r--r-- | rsa.cpp | 7 |
1 files changed, 6 insertions, 1 deletions
@@ -1,4 +1,5 @@ #include <algorithm> +#include <stdexcept> #include <cstdint> #include <cassert> #include "base64.h" @@ -26,7 +27,11 @@ namespace RSA{ pubkey.mod=privkey.mod=pq.first*pq.second; pubkey.exp=65537; Bigint x; - assert(egcd((pq.first-Bigint::one)*(pq.second-Bigint::one),pubkey.exp,x,privkey.exp)==1); + Bigint phi((pq.first-Bigint::one)*(pq.second-Bigint::one)); + assert(egcd(phi,pubkey.exp,x,privkey.exp)==1); + privkey.exp=privkey.exp.divmod(phi).second; + // cerr<<"pubkey = {"<<pubkey.mod<<" , "<<pubkey.exp<<'}'<<endl; + // cerr<<"privkey = {"<<privkey.mod<<" , "<<privkey.exp<<'}'<<endl; return make_pair(pubkey,privkey); } |