1using System;
2
3namespace PRCrack
4{
5 /// <summary>
6 /// Google PageRank的Checksum算法。
7 /// 作者:4111y80y
8 /// 日期:2005年1月20日
9 ///
email:sill...@china.com10 ///
注视:根据汇编改写,所以写的比较乱,希望不要介意
11 /// </summary>
12 class CheckSum
13 {
14 public CheckSum()
15 {
16 //
17 // TODO: 在此处添加构造函数逻辑
18 //
19 }
20
21 private Int64 sl(Int64 x, Int64 n)
22 {
23 Int64 sl;
24
25 if (n == 0)
26 {
27 sl = x;
28 }
29 else
30 {
31 Int64 k;
32 k = (Int64)Math.Pow(2,32 - n - 1);
33
34 Int64 d;
35 d = x & (k - 1);
36
37 Int64 c;
38 c = d * (Int64)Math.Pow(2,n);
39
40 if (Convert.ToBoolean(x & k))
41 {
42 c = c | Convert.ToInt32("0x80000000",16);
43 }
44
45 //Console.WriteLine("sl--c--"+c);
46
47 sl = c;
48 }
49
50 return sl;
51 }
52
53 private Int64 sr(Int64 x, Int64 n)
54 {
55 Int64 sr;
56
57 if (n == 0)
58 {
59 sr = x;
60 }
61 else
62 {
63 Int64 y;
64 y = x & Convert.ToInt32("0x7FFFFFFF",16);
65 Int64 z;
66 if (n == 32 - 1)
67 {
68 z = 0;
69 }
70 else
71 {
72 z = y / (Int64)Math.Pow(2,n);
73 }
74 if (y != x)
75 {
76 z = z | (Int64)Math.Pow(2,32-n-1); 77 }
78 sr = z;
79 }
80
81 return sr;
82 }
83
84 private Int64 zeroFill(Int64 a, Int64 b)
85 {
86 Int64 x;
87 if (Convert.ToBoolean(Convert.ToInt32("0x80000000",16) & a))
88 {
89 x = sr(a,1);
90 x = x & (~(Convert.ToInt32("0x80000000",16)));
91 x = x | Convert.ToInt32("0x40000000",16);
92 x = sr(x,b-1);
93 }
94 else
95 {
96 x = sr(a,b);
97 }
98
99 return x;
100 }
101
102 private Int64 uadd(Int64 L1, Int64 L2)
103 {
104
105 Int64 uadd;
106
107 Int64 L11, L12, L21, L22, L31, L32;
108 L11 = L1 & Convert.ToInt32("0xFFFFFF",16);
109
110 L12 = (L1 & Convert.ToInt32("0x7F000000",16)) /
Convert.ToInt32("0x1000000",16);
111
112 if (L1 < 0)
113 {
114 L12 = L12 | Convert.ToInt32("0x80",16);
115 }
116
117 L21 = L2 & Convert.ToInt32("0xFFFFFF",16);
118 L22 = (L2 & Convert.ToInt32("0x7F000000",16)) /
Convert.ToInt32("0x1000000",16);
119
120 if (L2 < 0)
121 {
122 L22 = L22 | Convert.ToInt32("0x80",16);
123 }
124
125
126
127 L32 = L12 + L22;
128 L31 = L11 + L21;
129
130 if (Convert.ToBoolean(L31 & Convert.ToInt32("0x1000000",16)))
131 {
132 L32 = L32 + 1;
133 }
134
135 uadd = (L31 & Convert.ToInt32("0xFFFFFF",16)) + (L32 &
Convert.ToInt32("0x7F",16)) * Convert.ToInt32("0x1000000",16);
136 if (Convert.ToBoolean(L32 & Convert.ToInt32("0x80",16)))
137 {
138 uadd = uadd | Convert.ToInt32("0x80000000",16);
139 }
140
141 return uadd;
142 }
143
144 private Int64 usub(Int64 L1, Int64 L2)
145 {
146 Int64 usub;
147
148 Int64 L11, L12, L21, L22, L31, L32;
149 L11 = L1 & Convert.ToInt32("0xFFFFFF",16);
150
151 L12 = (L1 & Convert.ToInt32("0x7F000000",16)) /
Convert.ToInt32("0x1000000",16);
152
153 if (L1 < 0)
154 {
155 L12 = L12 | Convert.ToInt32("0x80",16);
156 }
157
158 L21 = L2 & Convert.ToInt32("0xFFFFFF",16);
159 L22 = (L2 & Convert.ToInt32("0x7F000000",16)) /
Convert.ToInt32("0x1000000",16);
160
161 if (L2 < 0)
162 {
163 L22 = L22 | Convert.ToInt32("0x80",16);
164 };
165
166 L32 = L12 - L22;
167 L31 = L11 - L21;
168
169 if (L31 < 0 )
170 {
171 L32 = L32 - 1;
172 L31 = L31 + Convert.ToInt32("0x1000000",16);
173 }
174
175 usub = L31 + (L32 & 0x7F) * Convert.ToInt32("0x1000000",16);
176
177 if (Convert.ToBoolean(L32 & Convert.ToInt32("0x80",16)))
178 {
179 usub = usub | Convert.ToInt32("0x80000000",16);
180 }
181
182 return usub;
183 }
184
185 private Int64[] mix(Int64 ia, Int64 ib, Int64 ic)
186 {
187 Int64 a, b, c;
188 a = ia;
189 b = ib;
190 c = ic;
191
192 a = usub(a,b);
193
194 a = usub(a,c);
195
196 a = a ^ zeroFill(c,13);
197
198
199 b = usub(b,c);
200 b = usub(b,a);
201
202 b = b ^ sl(a,8);
203
204
205 c = usub(c,a);
206 c = usub(c,b);
207 c = c ^ zeroFill(b,13);
208
209
210 a = usub(a,b);
211 a = usub(a,c);
212 a = a ^ zeroFill(c,12);
213
214 b = usub(b,c);
215 b = usub(b,a);
216 b = b ^ sl(a,16);
217
218 c = usub(c,a);
219 c = usub(c,b);
220 c = c ^ zeroFill(b,5);
221
222 a = usub(a,b);
223 a = usub(a,c);
224 a = a ^ zeroFill(c,3);
225
226 b = usub(b,c);
227 b = usub(b,a);
228 b = b ^ sl(a,10);
229
230 c = usub(c,a);
231 c = usub(c,b);
232 c = c ^ zeroFill(b,15);
233
234 Int64[] ret=new Int64[3];
235
236 ret[0] = a;
237 ret[1] = b;
238 ret[2] = c;
239
240 return ret;
241 }
242
243 public static int Asc(string character)
244 {
245 if (character.Length == 1)
246 {
247 System.Text.ASCIIEncoding asciiEncoding = new
System.Text.ASCIIEncoding();
248 int intAsciiCode =
Convert.ToInt32(asciiEncoding.GetBytes(character)[0]);
249 return (intAsciiCode);
250 }
251 else
252 {
253 throw new Exception("Character is not valid.");
254 }
255
256 }
257
258 public static string Chr(Int64 asciiCode)
259 {
260 if (asciiCode >= 0 && asciiCode <= 255)
261 {
262 System.Text.ASCIIEncoding asciiEncoding = new
System.Text.ASCIIEncoding();
263 byte[] byteArray = new byte[]{(byte)asciiCode};
264 string strCharacter = asciiEncoding.GetString(byteArray);
265 return (strCharacter);
266 }
267 else
268 {
269 throw new Exception("ASCII Code is not valid.");
270 }
271 }
272
273 private Int64 gc(string s, int i)
274 {
275 int gc = Asc(s.Substring(i,1));
276
277 return gc;
278 }
279
280 private Int64 GoogleCH(string sURL)
281 {
282 Int64 iLength, a, b, c, iLen;
283 int k;
284 Int64[] m;
285 iLength = sURL.Length;
286
287 a = Convert.ToInt32("0x9E3779B9",16);
288 b = Convert.ToInt32("0x9E3779B9",16);
289 c = Convert.ToInt32("0xE6359A60",16);
290 k = 0;
291
292 iLen = iLength;
293
294 while(iLen >= 12)
295 {
296
297 a =
uadd(a,(uadd(gc(sURL,k+0),uadd(sl(gc(sURL,k+1),8),uadd(sl(gc(sURL,k+2),16),sl(gc(sURL,k+3),24))))));
298
299 b =
uadd(Convert.ToInt32(b),(uadd(gc(sURL,k+4),uadd(sl(gc(sURL,k+5),8),uadd(sl(gc(sURL,k+6),16),sl(gc(sURL,k+7),24))))));
300
301 c =
uadd(c,(uadd(gc(sURL,k+8),uadd(sl(gc(sURL,k+9),8),uadd(sl(gc(sURL,k+10),16),sl(gc(sURL,k+11),24))))));
302 m = mix(a,b,c);
303
304 a = m[0];
305
306 b = m[1];
307
308 c = m[2];
309
310
311 k = k + 12;
312
313 iLen = iLen - 12;
314 };
315
316 c = uadd(c,iLength);
317
318 switch(iLen)
319 {
320 case 11:
321 c = uadd(c,sl(gc(sURL,k+10),24));
322 c = uadd(c,sl(gc(sURL,k+9),16));
323 c = uadd(c,sl(gc(sURL,k+8),8));
324 b = uadd(b,sl(gc(sURL,k+7),24));
325 b = uadd(b,sl(gc(sURL,k+6),16));
326 b = uadd(b,sl(gc(sURL,k+5),8));
327 b = uadd(b,gc(sURL,k+4));
328 a = uadd(a,sl(gc(sURL,k+3),24));
329 a = uadd(a,sl(gc(sURL,k+2),16));
330 a = uadd(a,sl(gc(sURL,k+1),8));
331 a = uadd(a,gc(sURL,k+0));
332 break;
333 case 10:
334 c = uadd(c,sl(gc(sURL,k+9),16));
335 c = uadd(c,sl(gc(sURL,k+8),8));
336 b = uadd(b,sl(gc(sURL,k+7),24));
337 b = uadd(b,sl(gc(sURL,k+6),16));
338 b = uadd(b,sl(gc(sURL,k+5),8));
339 b = uadd(b,gc(sURL,k+4));
340 a = uadd(a,sl(gc(sURL,k+3),24));
341 a = uadd(a,sl(gc(sURL,k+2),16));
342 a = uadd(a,sl(gc(sURL,k+1),8));
343 a = uadd(a,gc(sURL,k+0));
344 break;
345 case 9:
346 c = uadd(c,sl(gc(sURL,k+8),8));
347 b = uadd(b,sl(gc(sURL,k+7),24));
348 b = uadd(b,sl(gc(sURL,k+6),16));
349 b = uadd(b,sl(gc(sURL,k+5),8));
350 b = uadd(b,gc(sURL,k+4));
351 a = uadd(a,sl(gc(sURL,k+3),24));
352 a = uadd(a,sl(gc(sURL,k+2),16));
353 a = uadd(a,sl(gc(sURL,k+1),8));
354 a = uadd(a,gc(sURL,k+0));