From 0a4dd8a99c370ed70330f61646b6dc8505546445 Mon Sep 17 00:00:00 2001 From: avinal <185067@nith.ac.in> Date: Sun, 21 Mar 2021 23:53:09 +0530 Subject: [PATCH] implement decrypt method --- src/Encryptor.cpp | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/Encryptor.cpp b/src/Encryptor.cpp index 301a778..94a5ab7 100644 --- a/src/Encryptor.cpp +++ b/src/Encryptor.cpp @@ -36,8 +36,28 @@ uint64_t Encryptor::blowfish_encrypt(std::vector &input_buf, return input_buf.size(); } -uint64_t Encryptor::blowfish_decrypt(std::vector const &input_buf, - std::string const &key, uint64_t in_size){ - - } +uint64_t Encryptor::blowfish_decrypt(std::vector &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