diff options
-rw-r--r-- | aes.cpp | 12 | ||||
-rw-r--r-- | aes.h | 4 | ||||
-rw-r--r-- | main.cpp | 4 | ||||
-rw-r--r-- | rsa.cpp | 6 | ||||
-rw-r--r-- | rsa.h | 4 |
5 files changed, 16 insertions, 14 deletions
@@ -174,7 +174,7 @@ namespace AES{ addRoundKey(state,keysched); } - string encryptCBC(const string &key,const string &data,int numrounds){ + string encryptCBC(const string &data,const string &key,int numrounds){ if(roundconstant[0]==0)initTables(); int sz=data.size(); @@ -211,7 +211,7 @@ namespace AES{ return res; } - string decryptCBC(const string &key,const string &data,int numrounds){ + string decryptCBC(const string &data,const string &key,int numrounds){ if(roundconstant[0]==0)initTables(); if(data.size()==0)return {}; @@ -232,7 +232,7 @@ namespace AES{ return res; } - string encrypt(const string &key,const string &data,Algorithm algo){ + string encrypt(const string &data,const string &key,Algorithm algo){ int increment; switch(algo){ case AES_128_CBC: increment=0; break; @@ -241,10 +241,10 @@ namespace AES{ default: assert(false); } assert((int)key.size()==4*(4+2*increment)); - return encryptCBC(key,data,10+2*increment); + return encryptCBC(data,key,10+2*increment); } - string decrypt(const string &key,const string &data,Algorithm algo){ + string decrypt(const string &data,const string &key,Algorithm algo){ int increment; switch(algo){ case AES_128_CBC: increment=0; break; @@ -253,7 +253,7 @@ namespace AES{ default: assert(false); } assert((int)key.size()==4*(4+2*increment)); - return decryptCBC(key,data,10+2*increment); + return decryptCBC(data,key,10+2*increment); } void test(){ @@ -10,10 +10,10 @@ namespace AES{ AES_256_CBC, }; - std::string encrypt(const std::string &key,const std::string &data,Algorithm algo); + std::string encrypt(const std::string &data,const std::string &key,Algorithm algo); //throws invalid_argument for an invalid ciphertext (length not a multiple of block size, or padding malformed) - std::string decrypt(const std::string &key,const std::string &data,Algorithm algo); + std::string decrypt(const std::string &data,const std::string &key,Algorithm algo); void test(); @@ -143,9 +143,9 @@ void performrsa(){ cout<<"d = "<<privkey.pexp<<endl; Bigint msg(123456789); cout<<"msg = "<<msg<<endl; - Bigint encr=RSA::encrypt(privkey.pub,msg); + Bigint encr=RSA::encrypt(msg,privkey.pub); cout<<"encr = "<<encr<<endl; - Bigint msg2=RSA::decrypt(privkey,encr); + Bigint msg2=RSA::decrypt(encr,privkey); cout<<"msg = "<<msg2<<endl; } @@ -10,12 +10,14 @@ using namespace std; namespace RSA{ - Bigint encrypt(const PublicKey &pubkey,Bigint msg){ + Bigint encrypt(Bigint msg,const PublicKey &pubkey){ + // cerr<<"msg="<<msg<<endl; + // cerr<<"mod="<<pubkey.mod<<endl; assert(msg>1&&msg<pubkey.mod); return expmod(msg,pubkey.exp,pubkey.mod); } - Bigint decrypt(const PrivateKey &privkey,Bigint encr){ + Bigint decrypt(Bigint encr,const PrivateKey &privkey){ return expmod(encr,privkey.pexp,privkey.pub.mod); } @@ -15,8 +15,8 @@ namespace RSA{ Bigint pexp; }; - Bigint encrypt(const PublicKey &key,Bigint msg); - Bigint decrypt(const PrivateKey &key,Bigint msg); + Bigint encrypt(Bigint msg,const PublicKey &key); + Bigint decrypt(Bigint msg,const PrivateKey &key); PrivateKey genkey(int nbits); //nbits is target number of bits of modulus PrivateKey genkey(int nbits,const std::string &password); //generates key seeded by password |