-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreflector.cpp
More file actions
55 lines (48 loc) · 1.43 KB
/
Copy pathreflector.cpp
File metadata and controls
55 lines (48 loc) · 1.43 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 "reflector.h"
#include "errors.h"
using namespace std;
Reflector::Reflector(string const& call_string){
int count = 0;
string rf_digit_string;
ifstream is_reflector;
is_reflector.open(call_string, ios::in);
if (!is_reflector){
exit_code = ERROR_OPENING_CONFIGURATION_FILE;
}
is_reflector >> rf_digit_string;
while (!exit_code && !is_reflector.eof()){
if (!exit_code)
is_numeric(rf_digit_string, exit_code);
if (!exit_code)
input_in_range(rf_digit_string, exit_code);
if (!exit_code)
rf_configuration[count] = stoi(rf_digit_string);
if (!exit_code){
if (!is_repetitive(count, rf_configuration))
exit_code = INVALID_REFLECTOR_MAPPING;
}
if (!exit_code)
is_reflector >> rf_digit_string;
count++;
if (!exit_code && count >= ALPHABET && !is_reflector.eof())
exit_code = INCORRECT_NUMBER_OF_REFLECTOR_PARAMETERS;
}
if (!exit_code && count < ALPHABET)
exit_code = INCORRECT_NUMBER_OF_REFLECTOR_PARAMETERS;
is_reflector.close();
}
/*End of Function*/
int Reflector::encrypt(int digit){
int remainder;
for (int i = 0 ; i < ALPHABET ; i++){
if (this->rf_configuration[i] == digit){
remainder = i % 2;
if (!remainder)
return (this->rf_configuration[i+1]);
if (remainder)
return (this->rf_configuration[i-1]);
}
}
return digit;//Not reachable since above is MECE. Included to suppress warning
}
/*End of Function*/