PHP数学运算代码转换成asp代码

2018-09-06 13:17

阅读:580

  今天考试过后(考的很悲剧),逛论坛看见一贴,说是转换一段asp代码为php代码:
01<?php
02function app_hash_url($url) {
03 $seed = "Mining PageRank is AGAINST GOOGLE'S TERMS OF SERVICE.";
04 $result = 0x01020345;
05 for ($i=0; $i<strlen($url); $i++) {
06 $result ^= ord($seed{$i%87}) ^ ord($url{$i});
07 $result = (($result >> 23) 0x1FF) $result << 9;
08 }
09 return sprintf("8%x", $result);
10}
11$url="dddddd";
12echo app_hash_url($url);
13?>
转换如下:
1.asp没有位移运算,百度了一个位移运算的类
2.格式化输出
01<%
02Class mShift
03
04 Private m_lPower2(31)
05
06 Public Function RShift(ByVal lThis, ByVal lBits)
07 On Error Resume Next
08 Init
09 If (lBits <= 0) Then
10 RShift = lThis
11 ElseIf (lBits > 63) Then
12 ' .. error ...
13 ElseIf (lBits > 31) Then
14 RShift = 0
15 Else
16 If (lThis And m_lPower2(31 - lBits)) = m_lPower2(31 - lBits) Then
17 RShift = (lThis And (m_lPower2(31 - lBits) - 1)) * m_lPower2(lBits)Or m_lPower2(31)
18 Else
19 RShift = (lThis And (m_lPower2(31 - lBits) - 1)) * m_lPower2(lBits)
20 End If
21 End If
22 End Function
23
24 Public Function LShift(ByVal lThis, ByVal lBits)
25 On Error Resume Next
26 Init
27 If (lBits <= 0) Then
28 LShift = lThis
29 ElseIf (lBits > 63) Then
30 ' ... error ...
31 ElseIf (lBits > 31) Then
32 LShift = 0
33 Else
34 If (lThis And m_lPower2(31)) = m_lPower2(31) Then
35 LShift = (lThis And H7FFFFFFF) \ m_lPower2(lBits) Or m_lPower2(31 - lBits)
36 Else
37 LShift = lThis \ m_lPower2(lBits)
38 End If
39 End If
40 End Function
41
42 Private Sub Init()
43 On Error Resume Next
44 m_lPower2(0) = H1
45 m_lPower2(1) = H2
46 m_lPower2(2) = H4
47 m_lPower2(3) = H8
48 m_lPower2(4) = H10
49 m_lPower2(5) = H20
50 m_lPower2(6) = H40
51 m_lPower2(7) = H80
52 m_lPower2(8) = H100
53 m_lPower2(9) = H200
54 m_lPower2(10) = H400
55 m_lPower2(11) = H800
56 m_lPower2(12) = H1000
57 m_lPower2(13) = H2000
58 m_lPower2(14) = H4000
59 m_lPower2(15) = H8000
60 m_lPower2(16) = H10000
61 m_lPower2(17) = H20000
62 m_lPower2(18) = H40000
63 m_lPower2(19) = H80000
64 m_lPower2(20) = H100000
65 m_lPower2(21) = H200000
66 m_lPower2(22) = H400000
67 m_lPower2(23) = H800000
68 m_lPower2(24) = H1000000
69 m_lPower2(25) = H2000000
70 m_lPower2(26) = H4000000
71 m_lPower2(27) = H8000000
72 m_lPower2(28) = H10000000
73 m_lPower2(29) = H20000000
74 m_lPower2(30) = H40000000
75 m_lPower2(31) = H80000000
76 End Sub
77
78End Class
79'---------------------------------------------------------
80function app_hash_url(url)
81Dim sft
82Set sft = New mShift
83seed = "Mining PageRank is AGAINST GOOGLE'S TERMS OF SERVICE."
84result = H01020345
85for i=0 to len(url)-1
86 result1 = asc(mid(seed,(i mod 87)+1,1))
87 result2 = asc(mid(url,i+1,1))
88 result = result xor (result1 xor result2)
89 result = (sft.LShift(result,23) and H1FF) or sft.RShift(result,9)
90next
91Set sft = Nothing
92response.write "8" LCase(hex(result))
93end function
94'-----------------------------------------------------------------------
95url1="ddddddddd"
96response.write app_hash_url(url1)
97%>


评论


亲,登录后才可以留言!