-
Notifications
You must be signed in to change notification settings - Fork 1
/
process_file.cpp
75 lines (63 loc) · 2.6 KB
/
process_file.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/**
* @file main.cpp
* @brief AES Test File
*
* This file tests AES Implementation 128/192/256 bit modes.
*
* @author Tony Josi https://tonyjosi97.github.io/profile/
* @copyright Copyright (C) 2020 Tony Josi
* @bug No known bugs.
*/
#include "aes.hpp"
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <chrono>
#include <string>
using namespace symmetric_ciphers;
namespace {
constexpr uint8_t key_128_TRD[24] = "12345678123456781234567";
size_t get_File_Size(std::unique_ptr<FILE, decltype(&fclose)> &file_Ptr) {
size_t file_Size = 0;
fseek(file_Ptr.get(), 0, SEEK_END); // Jump to the end of the file
file_Size = static_cast<size_t>(ftell(file_Ptr.get())); // Get the current byte offset in the file
rewind(file_Ptr.get()); // Jump back to the beginning of the file
return file_Size;
}
size_t get_FSize(const char *f_Name) {
std::unique_ptr<FILE, decltype(&fclose)> ip_file_Ptr(fopen(f_Name, "rb"), &fclose);
return get_File_Size(ip_file_Ptr);
}
}
int main(int argc, char *argv[]) {
auto t1 = std::chrono::high_resolution_clock::now();
AES file_tests(key_size::AES_128);
if(argc > 2) {
if(strcmp(argv[1], "s") == 0)
std::cout<<get_FSize(argv[2])<<std::endl;
else if(argc > 3) {
//std::string pass_wd((char *) key_128_TRD), op_f_name(argv[3]);
if (strcmp(argv[1], "e") == 0) {
file_tests.encrpyt_file(argv[2], argv[3], key_128_TRD, 24);
//file_tests.encrpyt_file__pybind_target(argv[2], op_f_name + "pyb", pass_wd);
}
else if (strcmp(argv[1], "d") == 0) {
file_tests.decrpyt_file(argv[2], argv[3], key_128_TRD, 24);
//file_tests.decrpyt_file__pybind_target(argv[2], op_f_name + "pyb", pass_wd);
}
else if (strcmp(argv[1], "x") == 0) {
file_tests.threaded_file_io_algo(std::string(argv[2]), std::string(argv[3]), key_128_TRD, 24, aes_Action::_ENCRYPT_0__);
}
else if (strcmp(argv[1], "y") == 0) {
file_tests.threaded_file_io_algo(std::string(argv[2]), std::string(argv[3]), key_128_TRD, 24, aes_Action::_DECRYPT_1__);
}
}
else
std::cout<<"Invalid option\n";
}
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>\
( std::chrono::high_resolution_clock::now() - t1 ).count();
std::cout<<"\nDuration: "<<duration<<"\n";
return 0;
}