From eb966005ca1cea675b50226555e6771424dfcdf6 Mon Sep 17 00:00:00 2001 From: Avinal Kumar Date: Thu, 6 May 2021 23:40:17 +0530 Subject: [PATCH] add file decrypt and encryt driver code Signed-off-by: Avinal Kumar --- CMakeLists.txt | 2 -- src/Main.cpp | 13 +++++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d3a6f04..63d9483 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,5 +25,3 @@ file(GLOB KRYPTO_INC ${PROJECT_SOURCE_DIR}/include/*.h) add_executable(${PROJECT_NAME} ${KRYPTO_SRC} ${KRYPTO_INC}) target_include_directories(${PROJECT_NAME} PRIVATE blowfish/include PUBLIC include) target_link_libraries(${PROJECT_NAME} blowfish) - - diff --git a/src/Main.cpp b/src/Main.cpp index fede8d6..72ad56b 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -21,9 +21,14 @@ int main(int argc, char const *argv[]) { test.pad_input(buffer, stat.filesize); krypto::Encryptor encryptor; - // encryptor.blowfish_encrypt(buffer, password, stat.filesize); - encryptor.blowfish_decrypt(buffer,password,stat.filesize); - test.write_file(filename.substr(8) , buffer, stat.filesize); - + int pos; + if ((pos = filename.find("krypto")) != std::string::npos) { + encryptor.blowfish_decrypt(buffer, password, stat.filesize); + test.write_file(filename.substr(0, pos-1), buffer, stat.filesize); + } else { + encryptor.blowfish_encrypt(buffer, password, stat.filesize); + test.write_file(filename + ".krypto", buffer, stat.filesize); + } + return 0; }