Commit a19b0e87 authored by yiwenshao's avatar yiwenshao

more strong ASHE

parent 7bded8cb
#include"crypto/ASHE.hh"
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){
return (plaintext - bf.encrypt(IV) + bf.encrypt(IV-1))%ASHE_MAX;
......
......@@ -6,7 +6,7 @@ class ASHE{
static const unsigned long long ASHE_MAX;
std::string key;
blowfish bf;
int IV;
uint64_t IV;
public:
ASHE(std::string s,int i);
long encrypt(unsigned long long plaintext);
......
#include <vector>
#include <iostream>
#include "crypto/ASHE.hh"
#include "util/util.cc"
int main(){
std::vector<unsigned long long > plain{1u,2u,3u,4u,5u,6u,7u,8u,9u,10u};
std::vector<long> enc;
ASHE as("2222",1);
std::vector<ASHE*> ass;
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;
for(auto item:enc){
std::cout<<"enc:"<<item<<"dec:"<<as.decrypt(item)<<std::endl;
for(auto i=0u;i<enc.size();++i){
std::cout<<"enc:"<<enc[i]<<"dec:"<<ass[i]->decrypt(enc[i])<<std::endl;
}
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