-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.cpp
More file actions
55 lines (52 loc) · 1.26 KB
/
Copy pathMain.cpp
File metadata and controls
55 lines (52 loc) · 1.26 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
#include "Rotor.hpp"
#include "Plugboard.hpp"
#include "Enigma.hpp"
#include <stdexcept>
#include <fstream>
#include <string>
#include <stdexcept>
using namespace std;
vector<int> parseFile(char* filename)
{
ifstream infile(filename);
if(infile.fail())
{
throw invalid_argument("Filed to open file; please check paths are correct");
}
int n;
vector<int> nums;
while(infile >> n)
{
nums.push_back(n);
}
return nums;
}
int main(int argc, char **argv)
{
if(argc == 1)
{
throw invalid_argument("You must input a pulgboard!");
}
vector<Rotor> rotors;
for(int i = 1; i < argc - 1; i++)
{
rotors.push_back(Rotor(parseFile(argv[i])));
}
Plugboard plugboard (parseFile(argv[argc - 1]));
Enigma enigma (rotors, plugboard);
string input;
while (getline(cin, input))
{
vector<int> toEncode;
for(string::size_type i = 0; i < input.size(); ++i) {
if(isupper(input[i]))
{
cout << (char) (enigma.encode(input[i] - 65) + 65);
} else if(!iswspace(input[i]))
{
throw invalid_argument("Input must either be upper case letter or whitespace");
}
}
}
return 0;
}