-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.cpp
More file actions
53 lines (50 loc) · 1.22 KB
/
Copy pathMain.cpp
File metadata and controls
53 lines (50 loc) · 1.22 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
#include <stdexcept>
#include <iostream>
#include <fstream>
#include "Enigma.hpp"
#include "Rotor.hpp"
#include "Plugboard.hpp"
using namespace std;
int main(int argc, char **argv)
{
if(argc > 1)
{
Enigma* enigma_machine = new Enigma(argc - 2);
for(int i = 1; i < argc - 1; i++)
{
ifstream in(argv[i]);
vector<int> configuration;
int letter_index;
int position = 0;
while(in >> letter_index)
{
configuration.push_back(letter_index);
}
Rotor r;
r.setMapping(configuration);
enigma_machine->addRotor(r);
}
Plugboard p;
ifstream in(argv[argc - 1]);
if(in.is_open())
{
int x, y; //elements of the next pair
while(in >> x >> y)
{
p.addToMap('A' + x, 'A' + y);
}
enigma_machine->addPlugboard(p);
}
else
{
throw invalid_argument(argv[argc - 1]);
}
enigma_machine->operate();
delete enigma_machine;
}
else
{
throw invalid_argument("No configuration files provided");
}
return 0;
}