-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathciphers.h
94 lines (75 loc) · 2.11 KB
/
ciphers.h
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/**
* \file ciphers.h
*
* Ezt a fájlt be kell adni (fel kell tölteni) a megoldással.
*/
#ifndef CipherS_H
#define CipherS_H
#include <string>
#include <vector>
#include "memtrace.h"
/**
* Az ős osztály interfésze
*/
class Cipher {
public:
/**
* Titkosítja a kapott stringet
* @param message titkosítandó üzenet
* @return a message szöveg titkosított változata
*/
virtual std::string encode(const std::string& message) = 0;
/**
* Dekódolja a kapott stringet
* @param ciphertext titkosított üzenet
* @return a megfejtett nyílt szöveg
*/
virtual std::string decode(const std::string& ciphertext) = 0;
/**
* Létrehoz egy másolatot dinamikusan
* @return a létrehozott objektumra mutató pointer
*/
virtual Cipher* clone() const = 0;
/**
* Alap destruktor
*/
virtual ~Cipher() { };
};
//Osztályok, amiket meg kell csinálni a leírások és az osztálydiagram alapján
class CaesarCipher :public Cipher{
int shift;
public:
explicit CaesarCipher(int shift) {
while (shift < 0)
shift += 26;
this->shift = shift % 26;
}
std::string encode(const std::string& message) override;
std::string decode(const std::string& ciphertext) override;
Cipher* clone() const override;
};
class MyCipher :public Cipher{
std::string key;
int offset;
public:
explicit MyCipher(std::string key) :key(key), offset(0) {}
MyCipher(std::string key, int offset) :key(key) {
if (offset < 0)
this->offset = offset;
this->offset = offset % 26;
}
std::string encode(const std::string& message) override;
std::string decode(const std::string& ciphertext) override;
Cipher* clone() const override;
};
class CipherQueue :public Cipher{
std::vector<Cipher*> ciphers;
public:
CipherQueue() = default;
void add(Cipher* cipher);
std::string encode(const std::string& message) override;
std::string decode(const std::string& ciphertext) override;
Cipher* clone() const override;
~CipherQueue() override;
};
#endif