Commit a19b0e87 authored by yiwenshao's avatar yiwenshao

more strong ASHE

parent 7bded8cb
#include"crypto/ASHE.hh" #include"crypto/ASHE.hh"
const unsigned long long ASHE::ASHE_MAX = 0xffffffffffffffff; const unsigned long long ASHE::ASHE_MAX = 0xffffffffffffffff;
ASHE::ASHE(std::string s,int i):key(s),bf(s),IV(i){} ASHE::ASHE(std::string s,int i):key(s),bf(s),IV(i){
}
long ASHE::encrypt(unsigned long long plaintext){ long ASHE::encrypt(unsigned long long plaintext){
return (plaintext - bf.encrypt(IV) + bf.encrypt(IV-1))%ASHE_MAX; return (plaintext - bf.encrypt(IV) + bf.encrypt(IV-1))%ASHE_MAX;
......
...@@ -6,7 +6,7 @@ class ASHE{ ...@@ -6,7 +6,7 @@ class ASHE{
static const unsigned long long ASHE_MAX; static const unsigned long long ASHE_MAX;
std::string key; std::string key;
blowfish bf; blowfish bf;
int IV; uint64_t IV;
public: public:
ASHE(std::string s,int i); ASHE(std::string s,int i);
long encrypt(unsigned long long plaintext); long encrypt(unsigned long long plaintext);
......
#include <vector> #include <vector>
#include <iostream> #include <iostream>
#include "crypto/ASHE.hh" #include "crypto/ASHE.hh"
#include "util/util.cc"
int main(){ int main(){
std::vector<unsigned long long > plain{1u,2u,3u,4u,5u,6u,7u,8u,9u,10u}; std::vector<unsigned long long > plain{1u,2u,3u,4u,5u,6u,7u,8u,9u,10u};
std::vector<long> enc; std::vector<long> enc;
ASHE as("2222",1); std::vector<ASHE*> ass;
for(auto item:plain){ for(auto item:plain){
enc.push_back(as.encrypt(item)); uint64_t IV = randomValue();
if(IV==0) IV=1;
ass.push_back(new ASHE("111",IV));
enc.push_back(ass.back()->encrypt(item));
} }
std::cout<<"encs:plains"<<std::endl; std::cout<<"encs:plains"<<std::endl;
for(auto item:enc){ for(auto i=0u;i<enc.size();++i){
std::cout<<"enc:"<<item<<"dec:"<<as.decrypt(item)<<std::endl; std::cout<<"enc:"<<enc[i]<<"dec:"<<ass[i]->decrypt(enc[i])<<std::endl;
} }
return 0; return 0;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment