将JS脚本转换成对应的VB代码
第一段:functionsafe_add(x,y){varlsw=(x&0xFFFF)+(y&0xFFFF);varmsw=(x>>16)+(y>>16)+(lsw>>1...
第一段:function safe_add(x, y)
{
var lsw = (x & 0xFFFF) + (y & 0xFFFF);
var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
return (msw << 16) | (lsw & 0xFFFF);
}第二段:function core_md5(x, len)
{
x[len >> 5] |= 128 << (len % 32);
x[(((len + 64) >>> 9) << 4) + 14] = len;
//省略部分}大家谁能帮我把这两小段转成对应VB代码呢,谢谢啦! 展开
{
var lsw = (x & 0xFFFF) + (y & 0xFFFF);
var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
return (msw << 16) | (lsw & 0xFFFF);
}第二段:function core_md5(x, len)
{
x[len >> 5] |= 128 << (len % 32);
x[(((len + 64) >>> 9) << 4) + 14] = len;
//省略部分}大家谁能帮我把这两小段转成对应VB代码呢,谢谢啦! 展开
2个回答
2013-12-02
展开全部
vb6里没有移位的操作,所以还是比较麻烦的
我从别处抄了一段移位的代码,然后在这个基础上修改了下
Private OnBits(0 To 31) As Long
Function safe_add(ByVal x As Long, y As Long)
Dim lsw As Long, msw As Long, result As Long
lsw = (x And &HFFFF) + (y And &HFFFF)
msw = shr(x, 16) + shr(y, 16) + shr(lsw, 16)
safe_add = shl(msw, 16) Or (lsw And &HFFFF)
End Function
Function core_md5(ByRef x() As Long, length As Long)
x(shr(length, 5)) = x(shr(length, 5)) Or shl(128, length Mod 32)
x(shl(shr((length + 64), 9), 4) + 14) = length
'省略
End Function
Function shl(ByVal Value As Long, ByVal Shift As Integer) As Long
MakeOnBits
If (Value And (2 ^ (31 - Shift))) Then GoTo OverFlow
shl = ((Value And OnBits(31 - Shift)) * (2 ^ Shift))
Exit Function
OverFlow:
shl = ((Value And OnBits(31 - (Shift + 1))) * _
(2 ^ (Shift))) Or &H80000000
End Function
Function shr(ByVal Value As Long, ByVal Shift As Integer) As Long
Dim hi As Long
MakeOnBits
If (Value And &H80000000) Then hi = &H40000000
shr = (Value And &H7FFFFFFE) \ (2 ^ Shift)
shr = (shr Or (hi \ (2 ^ (Shift - 1))))
End Function
Sub MakeOnBits()
Dim j As Integer, v As Long
For j = 0 To 30
v = v + (2 ^ j)
OnBits(j) = v
Next j
OnBits(j) = v + &H80000000
End Sub
我从别处抄了一段移位的代码,然后在这个基础上修改了下
Private OnBits(0 To 31) As Long
Function safe_add(ByVal x As Long, y As Long)
Dim lsw As Long, msw As Long, result As Long
lsw = (x And &HFFFF) + (y And &HFFFF)
msw = shr(x, 16) + shr(y, 16) + shr(lsw, 16)
safe_add = shl(msw, 16) Or (lsw And &HFFFF)
End Function
Function core_md5(ByRef x() As Long, length As Long)
x(shr(length, 5)) = x(shr(length, 5)) Or shl(128, length Mod 32)
x(shl(shr((length + 64), 9), 4) + 14) = length
'省略
End Function
Function shl(ByVal Value As Long, ByVal Shift As Integer) As Long
MakeOnBits
If (Value And (2 ^ (31 - Shift))) Then GoTo OverFlow
shl = ((Value And OnBits(31 - Shift)) * (2 ^ Shift))
Exit Function
OverFlow:
shl = ((Value And OnBits(31 - (Shift + 1))) * _
(2 ^ (Shift))) Or &H80000000
End Function
Function shr(ByVal Value As Long, ByVal Shift As Integer) As Long
Dim hi As Long
MakeOnBits
If (Value And &H80000000) Then hi = &H40000000
shr = (Value And &H7FFFFFFE) \ (2 ^ Shift)
shr = (shr Or (hi \ (2 ^ (Shift - 1))))
End Function
Sub MakeOnBits()
Dim j As Integer, v As Long
For j = 0 To 30
v = v + (2 ^ j)
OnBits(j) = v
Next j
OnBits(j) = v + &H80000000
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-12-02
展开全部
这个在VB中实现比较麻烦,在Vb中没有移位运算符,需要用除以2转化为2进制来模拟
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询