-
Notifications
You must be signed in to change notification settings - Fork 0
/
dm23_策略模式.cpp
76 lines (61 loc) · 1.06 KB
/
dm23_策略模式.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
74
75
76
#include <iostream>
using namespace std;
class Strategy
{
public:
virtual void crypt() = 0;
};
//对称加密 速度快 加密大数据块文件 特点:加密密钥和解密密钥是一样的.
//非对称加密 加密速度慢 加密强度高 高安全性高 ;特点: 加密密钥和解密密钥不一样 密钥对(公钥 和 私钥)
//
class AES : public Strategy
{
public:
virtual void crypt()
{
cout << "AES加密算法" << endl;
}
};
class DES : public Strategy
{
public:
virtual void crypt()
{
cout << "DES 加密算法" << endl;
}
};
class Context
{
public:
void setStrategy(Strategy *strategy)
{
this->strategy = strategy;
}
void myoperator()
{
strategy->crypt();
}
protected:
private:
Strategy *strategy;
};
void main()
{
/*
//1
DES *des = new DES;
des->crypt();
delete des;
*/
Strategy *strategy = NULL;
//strategy = new DES;
strategy = new AES;
Context *context = new Context;
context->setStrategy(strategy);
context->myoperator();
delete strategy;
delete context;
cout<<"hello..."<<endl;
system("pause");
return ;
}