mirror of
https://github.com/avinal/Krypto.git
synced 2026-01-09 22:58:36 +05:30
implement decrypt method
This commit is contained in:
@@ -36,8 +36,28 @@ uint64_t Encryptor::blowfish_encrypt(std::vector<char> &input_buf,
|
||||
return input_buf.size();
|
||||
}
|
||||
|
||||
uint64_t Encryptor::blowfish_decrypt(std::vector<char> const &input_buf,
|
||||
std::string const &key, uint64_t in_size){
|
||||
|
||||
}
|
||||
uint64_t Encryptor::blowfish_decrypt(std::vector<char> &input_buf,
|
||||
std::string const &key, uint64_t in_size) {
|
||||
uint32_t L = 0, R = 0;
|
||||
int block_size = sizeof(uint32_t);
|
||||
Blowfish blowfish(key);
|
||||
|
||||
for (size_t i = 0; i < in_size; i += (block_size * 2)) {
|
||||
L = str_to_uint32(
|
||||
std::string(input_buf.data() + i, input_buf.data() + i + block_size),
|
||||
block_size);
|
||||
R = str_to_uint32(std::string(input_buf.data() + i + block_size,
|
||||
input_buf.data() + i + 2 * block_size),
|
||||
block_size);
|
||||
blowfish.decrypt(L, R);
|
||||
std::string block = uint32_to_str(L, block_size);
|
||||
block += uint32_to_str(R, block_size);
|
||||
int j = i;
|
||||
std::for_each(block.begin(), block.end(), [&](char b) {
|
||||
input_buf[j] = b;
|
||||
j++;
|
||||
});
|
||||
}
|
||||
return input_buf.size();
|
||||
}
|
||||
} // namespace krypto
|
||||
|
||||
Reference in New Issue
Block a user