This repository has been archived by the owner on Aug 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
TaiNine.php
158 lines (137 loc) · 3.06 KB
/
TaiNine.php
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<?php
header("Content-type:text/html;charset=utf-8");
class TaiNine {
public $str;
function __construct() {
//81个原始字符数组
$KEY[0]="a";
$KEY[1]="b";
$KEY[2]="c";
$KEY[3]="d";
$KEY[4]="e";
$KEY[5]="f";
$KEY[6]="g";
$KEY[7]="h";
$KEY[8]="i";
$KEY[9]="j";
$KEY[10]="k";
$KEY[11]="l";
$KEY[12]="m";
$KEY[13]="n";
$KEY[14]="o";
$KEY[15]="p";
$KEY[16]="q";
$KEY[17]="r";
$KEY[18]="s";
$KEY[19]="t";
$KEY[20]="u";
$KEY[21]="v";
$KEY[22]="w";
$KEY[23]="x";
$KEY[24]="y";
$KEY[25]="z";
$KEY[26]="A";
$KEY[27]="B";
$KEY[28]="C";
$KEY[29]="D";
$KEY[30]="E";
$KEY[31]="F";
$KEY[32]="G";
$KEY[33]="H";
$KEY[34]="I";
$KEY[35]="J";
$KEY[36]="K";
$KEY[37]="L";
$KEY[38]="M";
$KEY[39]="N";
$KEY[40]="O";
$KEY[41]="P";
$KEY[42]="Q";
$KEY[43]="R";
$KEY[44]="S";
$KEY[45]="T";
$KEY[46]="U";
$KEY[47]="V";
$KEY[48]="W";
$KEY[49]="X";
$KEY[50]="Y";
$KEY[51]="Z";
$KEY[52]=",";
$KEY[53]=".";
$KEY[54]="?";
$KEY[55]="!";
$KEY[56]=":";
$KEY[57]=";";
$KEY[58]="+";
$KEY[59]="-";
$KEY[60]="*";
$KEY[61]="/";
$KEY[62]="^";
$KEY[63]="@";
$KEY[64]="0";
$KEY[65]="1";
$KEY[66]="2";
$KEY[67]="3";
$KEY[68]="4";
$KEY[69]="5";
$KEY[70]="6";
$KEY[71]="7";
$KEY[72]="8";
$KEY[73]="9";
$KEY[74]="%";
$KEY[75]="<";
$KEY[76]=">";
$KEY[77]="#";
$KEY[78]="$";
$KEY[79]="&";
$KEY[80]="=";
//深拷贝2个数组用来打乱和记录原始数据
for($i=0;$i<=80;$i++){
$this->encryptKey[$i]=$KEY[$i];
$this->originKey[$i]=$KEY[$i];
}
//每次打乱数组
shuffle($this->encryptKey);
//获取打乱数组的序列
for($i=0;$i<=80;$i++){
$encryMethod=$encryMethod.$this->encryptKey[$i];
}
$this->method=$encryMethod;
//获取正确序列数组的反序列
$this->underKey=array_flip($this->originKey);
}
//中文转换的函数用于加密和解密
function toHtml($string) {
return mb_convert_encoding($string,"HTML-ENTITIES","utf-8");
}
function backHtml($string) {
return mb_convert_encoding($string,"utf-8","HTML-ENTITIES");
}
//加密算法函数
function encrypt($str){
$str=$this->toHtml($str);
//打乱序列
for($i=0;$i<strlen($str);$i++){
//同余位次叠加加密法
$j=($this->underKey[$str[$i]]+$i)%81;
$encStr=$encStr.$this->encryptKey[$j];
}
$this->encryptData=$encStr;
}
function decrypt($str,$method){
for($i=0;$i<=80;$i++){
$decryKey[$i]=$method[$i];
}
$underDecryKey=array_flip($decryKey);
for($i=0;$i<strlen($str);$i++){
$j=$underDecryKey[$str[$i]]-$i;
while(($j<=-1) || ($j>=82)){
if($j<=-1) {$j=$j+81;}
if($j>=82) {$j=$j-81;}
}
$decryptData=$decryptData.$this->originKey[$j];
}
$this->decryptData=$this->backHtml($decryptData);
}
//class end
}