-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCXKUsername.cpp
More file actions
239 lines (225 loc) · 4.45 KB
/
CXKUsername.cpp
File metadata and controls
239 lines (225 loc) · 4.45 KB
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
//////////////////////////////////////////////////////////////////////////
// 星空用户名生成实现文件
// 作者:Huanfeng
// 版本:1.1
//////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "CXKUsername.h"
#include "MD5.h"
#include <cstring>
#include <time.h>
CXKUsername::CXKUsername(CString username, INT ver, long lasttimec)
:m_username(username),RADIUS("cqxinliradius002"),LR("\r\n")
{
m_ver = ver;
m_lasttimec = lasttimec;
}
long CXKUsername::GetLastTimeC()
{
return m_lasttimec;
}
CString CXKUsername::GetConnUsername()
{
time_t m_time; //得到系统时间,从1970.01.01.00:00:00 开始的秒数
long m_time1c; //时间初处理m_time1c为结果,经过时间计算出的第一次加密
long m_time1convert; //对时间操作后的结果,此为格式字串的原始数据
unsigned char ss[4] =
{
0,0,0,0
}; //源数据1,对m_time1convert进行计算得到格式符源数据
unsigned char ss2[4] =
{
0,0,0,0
}; //md5加密参数的一部分,m_time1c的字符形式
CString strS1; //md5加密参数的一部分,ss2的整体形式
CString m_formatsring; //由m_timece算出的字符串,一般为可视字符
CString m_md5; //对初加密(m_timec字符串表示+m_username+radius)的MD5加密
CString m_md5use; //md5 Lower模式的前两位
//取得系统时间m_time
time(&m_time);
//时间初处理m_time1c为结果,经过时间计算出的第一次加密
//子函数////////////////////////////
{
LONG64 t;
t = m_time;
t *= 0x66666667;
t >>= 0x20;
t >>= 0x01;
m_time1c = (long) t;
}
//5秒内动态用户名一致处理
if (m_time1c <= m_lasttimec)
{
m_time1c = m_lasttimec + 1;
}
m_lasttimec = m_time1c;
{
long t;
t = m_time1c;
ss2[3] = (t & 0xFF);
ss2[2] = (t & 0xFF00) / 0x100 ;
ss2[1] = (t & 0xFF0000) / 0x10000;
ss2[0] = (t & 0xFF000000) / 0x1000000;
{
//strS1必须用自加得到,真接加出问题
for (int i = 0; i < 4; i++)
{
strS1 += ss2[i];
}
}
}
/////////////////////////////////////
//倒置过程m_time1convert为结果
//子函数////////////////////////////
{
int t, t1, t2, t3;
t = m_time1c;
t1 = t;
t2 = t;
t3 = t;
t3 = t3 << 0x10;
t1 = t1 & 0x0FF00;
t1 = t1 | t3;
t3 = t;
t3 = t3 & 0x0FF0000;
t2 = t2 >> 0x10;
t3 = t3 | t2;
t1 = t1 << 0x08;
t3 = t3 >> 0x08;
t1 = t1 | t3;
m_time1convert = t1;
}
/////////////////////////////////////
//源数据1,对m_time1convert进行计算得到格式符源数据
//子函数////////////////////////////
{
long t;
t = m_time1convert;
ss[3] = (t & 0xFF);
ss[2] = (t & 0xFF00) / 0x100 ;
ss[1] = (t & 0xFF0000) / 0x10000;
ss[0] = (t & 0xFF000000) / 0x1000000;
}
/////////////////////////////////////
//格式符初加密
unsigned char pp[4] =
{
0,0,0,0
};
//子函数////////////////////////////
{
int i = 0, j = 0, k = 0;
for (i = 0; i < 0x20; i++)
{
j = i / 0x8;
k = 3 - (i % 0x4);
pp[k] *= 0x2;
if (ss[j] % 2 == 1)
{
pp[k]++;
}
ss[j] /= 2;
}
}
/////////////////////////////////////
//格式符计算,m_formatsring为结果
unsigned char pf[6] =
{
0,0,0,0,0,0
};
//子函数////////////////////////////
{
if(sizeof(int)==2){
int t1, t2;
t1 = pp[3];
t1 /= 0x4;
pf[0] = t1;
t1 = pp[3];
t1 = t1 & 0x3;
t1 *= 0x10;
pf[1] = t1;
t2 = pp[2];
t2 /= 0x10;
t2 = t2 | t1;
pf[1] = t2;
t1 = pp[2];
t1 = t1 & 0x0F;
t1 *= 0x04;
pf[2] = t1;
t2 = pp[1];
t2 /= 0x40;
t2 = t2 | t1;
pf[2] = t2;
t1 = pp[1];
t1 = t1 & 0x3F;
pf[3] = t1;
t2 = pp[0];
t2 /= 0x04;
pf[4] = t2;
t1 = pp[0];
t1 = t1 & 0x03;
t1 *= 0x10;
pf[5] = t1;
}
else{
short t1,t2 ;
t1 = pp[3];
t1 /= 0x4;
pf[0] = t1;
t1 = pp[3];
t1 = t1 & 0x3;
t1 *= 0x10;
pf[1] = t1;
t2 = pp[2];
t2 /= 0x10;
t2 = t2 | t1;
pf[1] = t2;
t1 = pp[2];
t1 = t1 & 0x0F;
t1 *= 0x04;
pf[2] = t1;
t2 = pp[1];
t2 /= 0x40;
t2 = t2 | t1;
pf[2] = t2;
t1 = pp[1];
t1 = t1 & 0x3F;
pf[3] = t1;
t2 = pp[0];
t2 /= 0x04;
pf[4] = t2;
t1 = pp[0];
t1 = t1 & 0x03;
t1 *= 0x10;
pf[5] = t1;
}
}
/////////////////////////////////////
{
int i;
for (i = 0; i < 6; i++)
{
pf[i] += 0x20;
if ((pf[i]) >= 0x40)
{
pf[i]++;
}
}
}
{
for (int i = 0; i < 6; i++)
{
m_formatsring += pf[i];
}
}
/////////////////////////////////////
CString strInput;
char temp[100];
strInput = strS1 + m_username.Left(m_username.FindOneOf("@")) + RADIUS;
strcpy_s(temp,strInput.c_str());
m_md5 = MD5String(temp);
m_md5use = m_md5.Left(2);
m_realusername = m_formatsring + m_md5use + m_username;
m_realusername = LR + m_realusername;//前面两位为回车换行0D0A,接着再是后续的
return m_realusername;
}