-
Notifications
You must be signed in to change notification settings - Fork 0
/
temp.cpp
54 lines (43 loc) · 1.53 KB
/
temp.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
# include <iostream>
// Base class for hashing strategies
class HashingStrategy {
public:
virtual ~HashingStrategy() {}
virtual void hashData(const std::string& data, std::string& hash) = 0;
};
// Subclasses for specific hashing algorithms (e.g., SHA-256, MD5)
class SHA256HashingStrategy : public HashingStrategy {
// Implement SHA-256 hashing
};
// Base class for encryption strategies
class EncryptionStrategy {
public:
virtual ~EncryptionStrategy() {}
virtual void encryptData(const std::string& plaintext, std::string& ciphertext) = 0;
virtual void decryptData(const std::string& ciphertext, std::string& plaintext) = 0;
};
// Subclasses for specific encryption algorithms (e.g., AES-256, RSA)
class AESEncryptionStrategy : public EncryptionStrategy {
// Implement AES-256 encryption and decryption
};
class Hashing {
private:
HashingStrategy* hashingStrategy;
public:
Hashing(HashingStrategy* strategy) : hashingStrategy(strategy) {}
void hashData(const std::string& data, std::string& hash) {
hashingStrategy->hashData(data, hash);
}
};
class Encryption {
private:
EncryptionStrategy* encryptionStrategy;
public:
Encryption(EncryptionStrategy* strategy) : encryptionStrategy(strategy) {}
void encryptData(const std::string& plaintext, std::string& ciphertext) {
encryptionStrategy->encryptData(plaintext, ciphertext);
}
void decryptData(const std::string& ciphertext, std::string& plaintext) {
encryptionStrategy->decryptData(ciphertext, plaintext);
}
};