-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rotor.cpp
75 lines (54 loc) · 1.3 KB
/
Rotor.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
//
// Created by Michal on 06.12.2018.
//
#include "Rotor.h"
char Rotor1[] = "EKMFLGDQVZNTOWYHXUSPAIBRCJ";
char Rotor2[] = "AJDKSIRUXBLHWTMCQGZNPYFVOE";
char Rotor3[] = "BDFHJLCPRTXVZNYEIWGAKMUSQO";
char Rotor4[] = "ESOVPZJAYQUIRHXLNFTGKDCMWB";
char Rotor5[] = "ESOVPZJAYQUIRHXLNFTGKDCMWB";
char Reflector[] = "YRUHQSLDPXNGOKMIEBFZCWVJAT";
Rotor::Rotor(int rotorType) {
loadRotor(rotorType);
}
void Rotor::loadRotor(int rotorType) {
switch (rotorType) {
case 1 :
setCypher(Rotor1);
break;
case 2 :
setCypher(Rotor2);
break;
case 3:
setCypher(Rotor3);
break;
case 4:
setCypher(Rotor4);
break;
case 5:
setCypher(Rotor5);
break;
case 6:
setCypher(Reflector);
break;
}
}
List<char> &Rotor::getCypher() {
return Cypher;
}
void Rotor::setCypher(char *tabPtr) {
Cypher.loadList(tabPtr);
}
Rotor &Rotor::operator=(Rotor &rotor) {
Cypher = rotor.Cypher;
return *this;
}
void Rotor::encrypt(char &letter) {
letter = Cypher.getData(letter - 65);
}
void Rotor::returnEncrypt(char &letter) {
letter = (char) (65 + Cypher.getNumb(letter));
}
void Rotor::moveRotor() {
Cypher.moveHead();
}