diff options
author | tomsmeding <tom.smeding@gmail.com> | 2016-10-09 10:34:25 +0200 |
---|---|---|
committer | tomsmeding <tom.smeding@gmail.com> | 2016-10-09 10:34:25 +0200 |
commit | 30c143c1d037b1a01ce69edd1b533878a959e8ff (patch) | |
tree | 0acd2a4c7f4bd8f8decaa8efe2d0926f7e2cc9e3 /rsa.cpp | |
parent | fc236266f7931cde83c5c136a0a4e0246ab018e0 (diff) |
Bugfixes and debugging
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); } |