[請益] Pack('H*') in classic asp

作者: sliceart (art)   2015-03-27 22:36:03
想請問若要在ASP中實作PACK()的話該怎麼做呢?
主要是為了將pack('H*',md5($str))實作在ASP中
在ASP內我先把md5的32個位元兩兩一組
再把這16組字串轉成數字,如33轉成51
然後再用chr()轉成ASCII,最後將這16個字元加起來
我這樣測試了幾筆資料,看起來是好像顯示出來的,PHP跟ASP都一樣
但是將解析出來的字串再透過MD5比對,PHP跟ASP的就天差地遠了
請問有沒有高手可解惑.....
謝謝
function PHP_PACK(str)
dim i , rtn , tmpA,tmpB
rtn = ""
For i = 1 to len(str) step 2
tmpA = mid(str,i,1)
tmpB = mid(str,i+1,1)
num = HexToTen(tmpA)*16+HexToTen(tmpB)
'response.write num&":"&chr(num)&"<br/>"
rtn = rtn & chr(num)
next
'response.write rtn & ":"&md5(rtn)&"<br/>"
PHP_PACK=rtn
end function
function HexToTen(str)
select case lcase(str)
case "1":rtn = 1
case "2":rtn = 2
case "3":rtn = 3
case "4":rtn = 4
case "5":rtn = 5
case "6":rtn = 6
case "7":rtn = 7
case "8":rtn = 8
case "9":rtn = 9
case "a":rtn = 10
case "b":rtn = 11
case "c":rtn = 12
case "d":rtn = 13
case "e":rtn = 14
case "f":rtn = 15
end select
HexToTen = rtn
end function

Links booklink

Contact Us: admin [ a t ] ucptt.com