-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
51 lines (43 loc) · 1.55 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <iostream>
#include <stdio.h>
#include <filesystem>
#include <string.h>
#include <sys/stat.h>
#include "encrypt.cpp"
using namespace std;
using namespace encryption;
namespace fs = std::filesystem;
int main() {
string directory;
cout << "Folder? ";
cin >> directory;
cout << "Folder selected - "+directory+"\n";
string key;
cout << "Key? ";
cin >> key;
cout << "Key selected - "+key+"\n";
EncryptionAlgorithm encryptor(key);
// get list of files
cout << "\nFetching files in folder...\n\n";
struct stat sb;
// loop files and apply change based on mode
for (const auto& entry : fs::directory_iterator(directory)) {
// Converting the path to const char * in the subsequent lines
std::filesystem::path outfilename = entry.path();
std::string outfilename_str = outfilename.string();
const char* path = outfilename_str.c_str();
// Testing whether the path points to a non-directory or not If it does, displays path
if (stat(path, &sb) == 0 && !(sb.st_mode & S_IFDIR))
std ::cout << path << std::endl;
string ext = outfilename.extension().string();
std ::cout << "Extension is "+ext+"\n";
// if not ub extension, set mode to encrypt
if (strcmp(ext.c_str(),".ub")){
encryptor.encrypt(outfilename_str.c_str());
}else{
// else set mode to decrypt
encryptor.decrypt(outfilename_str.c_str());
}
cout << "\n";
}
}