forked from philipperemy/easy-encryption
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcl.cpp
More file actions
67 lines (59 loc) · 1.25 KB
/
cl.cpp
File metadata and controls
67 lines (59 loc) · 1.25 KB
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
#include <stdio.h>
#include <string.h>
#include <string>
#include <iostream>
#include <stdio.h>
#include <ctype.h>
#include <fstream>
#include "encrypt.h"
using namespace std;
string load( const char* path )
{
FILE* src = fopen(path, "rb");
string res;
fseek(src,0,SEEK_END);
int size = ftell(src);
rewind( src );
res.resize(size);
fread(const_cast<char*>(res.data()), size, 1, src);
fclose(src);
return res;
}
void write( const char* path, string& str )
{
# if 1
FILE* fp = fopen( path, "wb" );
fwrite( str.c_str(), strlen( str.c_str() ), 1, fp );
fclose( fp );
#else
ofstream ofs(path);
ofs << str;
ofs.close();
#endif
}
int main(int argc, char** argv)
{
//ee64 src.txt dst.txt key 0
#if 1
std::string key = argv[3];
int encrypt_flag = atoi(argv[4]);
string src = load( argv[1] );
string dst;
if(encrypt_flag == 0) {
dst = encrypt(src, key);
} else {
dst = decrypt(src, key);
}
write( argv[2], dst );
#else
std::string msg = argv[1];
std::string key = argv[2];
int encrypt_flag = atoi(argv[3]);
if(encrypt_flag == 0) {
std::cout << encrypt(msg, key) << std::endl;
} else {
std::cout << decrypt(msg, key) << std::endl;
}
#endif
return 0;
}