Skip to content

Commit

Permalink
minor
Browse files Browse the repository at this point in the history
  • Loading branch information
smortezah committed Apr 17, 2020
1 parent 64b582e commit 7a1b7c5
Show file tree
Hide file tree
Showing 23 changed files with 200 additions and 94 deletions.
12 changes: 1 addition & 11 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
.vscode/*
build
cryfa
keygen

origin
*.fa
*.fq
in
fa
fq
mori
origfa
origfq
keygen
38 changes: 31 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,42 @@
cmake_minimum_required(VERSION 3.3.2)

project(cryfa)

SET(CMAKE_BUILD_TYPE Release)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pthread -O3")
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()

file(GLOB CRYPTOPP_SOURCE "src/cryptopp/*.cpp")
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED 11)
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
set(CMAKE_CXX_FLAGS_DEBUG "-g")

add_executable(cryfa
include_directories(${CMAKE_SOURCE_DIR}/src/include)

find_package(Threads REQUIRED)

file(GLOB CRYPTOPP_SOURCE "src/cryptopp/*.cpp")
add_library(libCryptopp OBJECT
${CRYPTOPP_SOURCE}
src/cryfa.cpp
)

add_library(libCryfaCommon OBJECT
src/endecrypto.cpp
src/fasta.cpp
src/fastq.cpp
src/security.cpp)
src/security.cpp
)

add_executable(cryfa
src/cryfa.cpp
)

target_link_libraries(cryfa
Threads::Threads
libCryfaCommon
libCryptopp
)

add_executable(keygen
src/keygen.cpp)
src/keygen.cpp
)
Binary file modified bin/linux/cryfa.tar.xz
Binary file not shown.
Binary file removed bin/linux/cryfa.zip
Binary file not shown.
Binary file modified bin/linux/keygen.tar.xz
Binary file not shown.
Binary file removed bin/linux/keygen.zip
Binary file not shown.
Binary file removed bin/macOS/cryfa.tar.xz
Binary file not shown.
Binary file removed bin/macOS/cryfa.zip
Binary file not shown.
Binary file removed bin/macOS/keygen.tar.xz
Binary file not shown.
Binary file removed bin/macOS/keygen.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

if [ ! -d build ]; then mkdir -p build; fi
cd build
# rm CMakeCache.txt
rm CMakeCache.txt
cmake ..
make -j4
mv cryfa ..
Expand Down
3 changes: 0 additions & 3 deletions src/application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ class application {

public:
application() = default;

void exe(int, char**);
};

Expand Down Expand Up @@ -83,11 +82,9 @@ void application::exe_decrypt_decompress() {
std::ifstream in(DEC_FNAME);
switch (in.peek()) {
case (char)127:
// std::cerr << "Decompressing...\n";
fa.decompress();
break;
case (char)126:
// std::cerr << "Decompressing...\n";
fq.decompress();
break;
case (char)125:
Expand Down
7 changes: 1 addition & 6 deletions src/def.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,6 @@ struct POWER<B, 0> {
LOOP(i, S) LOOP(j, S) LOOP6(k, l, m, n, o, p, S)
#define IGNORE_THIS_LINE(in) \
(in).ignore(std::numeric_limits<std::streamsize>::max(), '\n')
#define REWIND(in) \
{ \
(in).clear(); \
(in).seekg(0, std::ios::beg); \
}

// Constants
static const std::string THR_ID_HDR = "THRD="; /**< @brief Thread ID header */
Expand All @@ -81,7 +76,7 @@ static const std::string UPK_FNAME =
static const std::string USH_FNAME =
"CRYFA_USH"; /**< @brief Unshuffled file name*/
constexpr byte DEF_N_THR = 8; /**< @brief Default number of threads */
constexpr u64 BLOCK_SIZE = 8 * 1024; /**< @brief To read from input file*/
constexpr u64 BLOCK_SIZE = 8 * 1024; /**< @brief To read/write from/to file */
constexpr byte C1 = 2; /**< @brief Cat 1 = 2 */
constexpr byte C2 = 3; /**< @brief Cat 2 = 3 */
constexpr byte MIN_C3 = 4; /**< @brief 4 <= Cat 3 <= 6 */
Expand Down
79 changes: 59 additions & 20 deletions src/endecrypto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1018,7 +1018,6 @@ void EnDecrypto::unshuffle_block(byte threadID) {

// Write header containing threadID for each partially unshuffled file
ushfile << THR_ID_HDR + std::to_string(threadID) << '\n';

ushfile << unshText << '\n';

// Ignore to go to the next related chunk
Expand All @@ -1042,23 +1041,26 @@ void EnDecrypto::join_packed_files(const std::string& headers,
byte t; // For threads
std::ifstream pkFile[n_threads];
std::ofstream pckdFile(PCKD_FNAME); // Packed file
std::string content;
content.reserve(BLOCK_SIZE);
auto write_content = [&]() { pckdFile << content; };

switch (fT) {
case 'A':
pckdFile << (char)127;
content += (char)127;
break; // Fasta
case 'Q':
pckdFile << (char)126;
content += (char)126;
break; // Fastq
default:
break;
}
pckdFile << (!stop_shuffle ? (char)128 : (char)129);
pckdFile << headers;
pckdFile << (char)254; // To detect headers in decryptor
content += (!stop_shuffle ? (char)128 : (char)129);
content += headers;
content += (char)254; // To detect headers in decryptor
if (fT == 'Q') {
pckdFile << qscores;
pckdFile << (justPlus ? (char)253 : '\n');
content += qscores;
content += (justPlus ? (char)253 : '\n');
}

// Input files
Expand All @@ -1072,14 +1074,21 @@ void EnDecrypto::join_packed_files(const std::string& headers,

while (std::getline(pkFile[t], line).good() &&
line != THR_ID_HDR + std::to_string(t)) {
if (prevLineNotThrID) pckdFile << '\n';
pckdFile << line;
if (prevLineNotThrID) content += '\n';
content += line;

if (content.size() >= BLOCK_SIZE) {
write_content();
content.clear();
content.reserve(BLOCK_SIZE);
}

prevLineNotThrID = true;
}
}
}
pckdFile << (char)252;
content += (char)252;
write_content();

// Close/delete input/output files
pckdFile.close();
Expand All @@ -1098,6 +1107,9 @@ void EnDecrypto::join_unpacked_files() const {
byte t; // For threads
std::ifstream upkdFile[n_threads];
for (t = n_threads; t--;) upkdFile[t].open(UPK_FNAME + std::to_string(t));
std::string content;
content.reserve(BLOCK_SIZE);
auto write_content = [&]() { std::cout << content; };

bool prevLineNotThrID; // If previous line was "THRD=" or not
while (!upkdFile[0].eof()) {
Expand All @@ -1106,15 +1118,22 @@ void EnDecrypto::join_unpacked_files() const {

for (std::string line; std::getline(upkdFile[t], line).good() &&
line != THR_ID_HDR + std::to_string(t);) {
if (prevLineNotThrID) std::cout << '\n';
std::cout << line;
if (prevLineNotThrID) content += '\n';
content += line;

if (content.size() >= BLOCK_SIZE) {
write_content();
content.clear();
content.reserve(BLOCK_SIZE);
}

prevLineNotThrID = true;
}

if (prevLineNotThrID) std::cout << '\n';
if (prevLineNotThrID) content += '\n';
}
}
write_content();

// Close/delete input/output files
for (t = n_threads; t--;) {
Expand All @@ -1131,9 +1150,12 @@ void EnDecrypto::join_unpacked_files() const {
void EnDecrypto::join_shuffled_files() const {
std::ifstream shFile[n_threads];
std::ofstream shdFile(PCKD_FNAME); // Output Shuffled file
std::string content;
content.reserve(BLOCK_SIZE);
auto write_content = [&]() { shdFile << content; };

shdFile << (char)125;
shdFile << (!stop_shuffle ? (char)128 : (char)129);
content += (char)125;
content += (!stop_shuffle ? (char)128 : (char)129);

// Input files
for (byte t = n_threads; t--;) shFile[t].open(SH_FNAME + std::to_string(t));
Expand All @@ -1144,13 +1166,20 @@ void EnDecrypto::join_shuffled_files() const {

for (std::string line; std::getline(shFile[t], line).good() &&
line != THR_ID_HDR + std::to_string(t);) {
if (prevLineNotThrID) shdFile << '\n';
shdFile << line;
if (prevLineNotThrID) content += '\n';
content += line;

if (content.size() >= BLOCK_SIZE) {
write_content();
content.clear();
content.reserve(BLOCK_SIZE);
}

prevLineNotThrID = true;
}
}
}
write_content();

// Close/delete input/output files
shdFile.close();
Expand All @@ -1169,20 +1198,30 @@ void EnDecrypto::join_unshuffled_files() const {
byte t; // For threads
std::ifstream ushdFile[n_threads];
for (t = n_threads; t--;) ushdFile[t].open(USH_FNAME + std::to_string(t));
std::string content;
content.reserve(BLOCK_SIZE);
auto write_content = [&]() { std::cout << content; };

while (!ushdFile[0].eof()) {
for (t = 0; t != n_threads; ++t) {
bool prevLineNotThrID = false; // If previous line was "THR=" or not

for (std::string line; std::getline(ushdFile[t], line).good() &&
line != THR_ID_HDR + std::to_string(t);) {
if (prevLineNotThrID) std::cout << '\n';
std::cout << line;
if (prevLineNotThrID) content += '\n';
content += line;

if (content.size() >= BLOCK_SIZE) {
write_content();
content.clear();
content.reserve(BLOCK_SIZE);
}

prevLineNotThrID = true;
}
}
}
write_content();

// Close/delete input/output files
for (t = n_threads; t--;) {
Expand Down
Loading

0 comments on commit 7a1b7c5

Please sign in to comment.