-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rotor.hpp
44 lines (38 loc) · 1007 Bytes
/
Rotor.hpp
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
#ifndef ROTOR_HPP
#define ROTOR_HPP
#include <array>
#include <string>
#include <string_view>
constexpr std::array<std::string_view, 5> rotors =
{
// "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"EKMFLGDQVZNTOWYHXUSPAIBRCJ", //rotor I
"AJDKSIRUXBLHWTMCQGZNPYFVOE", //rotor II
"BDFHJLCPRTXVZNYEIWGAKMUSQO", //rotor III
"ESOVPZJAYQUIRHXLNFTGKDCMWB", //rotor IV
"VZBRGITYUPSDNHLXAWMJQOFECK" //rotor V
};
constexpr std::array<std::string_view, 5> inverseRotors =
{
// "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"UWYGADFPVZBECKMTHXSLRINQOJ",
"AJPCZWRLFBDKOTYUQGENHXMIVS",
"TAGBPCSDQEUFVNZHYIXJWLRKOM",
"HZWVARTNLGUPXQCEJMBSKDYOIF",
"QCYLXWENFTZOSMVJUDKGIARPHB"
};
class Rotor
{
private:
std::string rotor;
std::string inverseRotor;
public:
std::string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
std::string iAlphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char ring;
void setRotor(int);
void substitute(char &, char);
void offset();
void ringApply(char);
};
#endif