-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
75 lines (60 loc) · 1.8 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
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 <string>
#include "vigenere.hpp"
#include "ascii.hpp"
#include "clo.hpp"
#include <typeinfo> // typeid
using namespace std;
int main(int argc,char* argv[])
{
try
{
CLO Options(argc, argv);
string input = Options.Input();
string output;
string key = Options.key();
if(Options.Flag(CLO::HELP))
{
cout << Options.LoadFromFile("aide.txt") << endl;
}
if(Options.Flag(CLO::ENCIPHER))
{
cout << "Encipher..." << endl;
output = vigenere::encipher(ascii::fr_ref, input, key);
}
else if(Options.Flag(CLO::DECIPHER))
{
cout << "Decipher..." << endl;
if(Options.Flag(CLO::KEY_SIZE)) {
key = vigenere::break_key(ascii::fr_ref, input, Options.key_size());
}
else if(Options.Flag(CLO::UNKNOWN_KEY)) {
key = vigenere::break_key(ascii::fr_ref, input);
}
output = vigenere::decipher(ascii::fr_ref, input, key);
}
if(Options.Flag(CLO::OUTPUT_FILE))
{
Options.SaveInFile(Options.OutputFilename(),output);
cout << "Output saved in the following file : " << Options.OutputFilename() << "." << endl;
}
cout << "Key size : " << key.size() << endl;
cout << "Key : " << key << endl;
if(Options.Flag(CLO::VERBOSE))
{
cout << "Output : " << output << endl;
}
}
catch(const std::exception &E)
{
std::cout << "\n> Error : " << E.what() << "\n"
<< "> Exception : " << typeid(E).name() << std::endl;
return 1;
}
catch(...)
{
std::cout << "\n> Unknown error." << std::endl;
return 1;
}
return 0;
}