-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
76 lines (64 loc) · 1.84 KB
/
Copy pathmain.cpp
File metadata and controls
76 lines (64 loc) · 1.84 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
68
69
70
71
72
73
74
75
#include <iostream>
#include <vector>
#include <string>
#include <stdio.h>
#include "encrypting.h"
#include "cmdLineParser.h"
#include <termios.h>
#include <unistd.h>
#define DEBUG1
/***
XOR encryption by MAPster
ToDo:
include good random generator for long key generation
***/
/// public variables
int main(int argc, char** argv)
{
termios oldt;
tcgetattr(STDIN_FILENO, &oldt);
termios newt = oldt;
newt.c_lflag &= ~ECHO;
tcsetattr(STDIN_FILENO, TCSANOW, &newt);
bool filenameSet=true;
if(argc < 2)
filenameSet=false;
std::vector<std::string> arguments;
std::string fileName;
std::cout << "File encryption/decryption program using XOR algorithm" <<std::endl;
std::string key, key2;
std ::cout << "----------" << std::endl;
std::cout << "Now you are going to specify your key. You need to remember it in order to decrypt your files again." << std::endl
<< "Anyway, do NOT save your key next to the encrypted files. This would make the encryption useless." <<std::endl
<< "Please enter your key:" << std::endl;
getString(&key);
// get string second time
std::cout << "Please enter your key a second time:" << std::endl;
getString(&key2);
//restore terminal state
tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
if(key != key2)
{
std::cout << "Keys do not match. Abort" << std::endl;
return 1;
}
// don't keep double copy of string in memory
key2 = "dfhflesargfghrewhfaerhuflhesafkgfesaliufeafea43878956439875";
if(filenameSet==true)
{
arguments = readArguments(argc, argv);
for(int i=1; i<argc; i++)
{
std::cout << "Now encrypting: " << arguments.at(i) << std::endl;
encryptFile(arguments.at(i), key);
}
}
else
{
std::cout << "choose which file to encrypt" << std::endl;
std::cin >> fileName;
encryptFile(fileName, key);
}
std::cout << "operation succeeded" << std::endl;
return 0;
}