asp 一些支付接口(41)
lY8 = lY And &H80000000
lX4 = lX And &H40000000
lY4 = lY And &H40000000
lResult = (lX And &H3FFFFFFF) + (lY And &H3FFFFFFF)
If lX4 And lY4 Then
lResult = lResult Xor &H80000000 Xor lX8 Xor lY8
ElseIf lX4 Or lY4 Then
If lResult And &H40000000 Then
lResult = lResult Xor &HC0000000 Xor lX8 Xor lY8
Else
lResult = lResult Xor &H40000000 Xor lX8 Xor lY8
End If
Else
lResult = lResult Xor lX8 Xor lY8
End If
AddUnsigned = lResult
End Function
Function ConvertToWordArray(sMessage)
Dim lMessageLength
Dim lNumberOfWords
Dim lWordArray()
Dim lBytePosition
Dim lByteCount
Dim lWordCount
Const MODULUS_BITS = 512
Const CONGRUENT_BITS = 448
lMessageLength = Len(sMessage)
lNumberOfWords = (((lMessageLength + ((MODULUS_BITS - CONGRUENT_BITS) \ BITS_TO_A_BYTE)) \ (MODULUS_BITS \ BITS_TO_A_BYTE)) + 1) * (MODULUS_BITS \ BITS_TO_A_WORD)
ReDim lWordArray(lNumberOfWords - 1)
lBytePosition = 0
lByteCount = 0
Do Until lByteCount >= lMessageLength
lWordCount = lByteCount \ BYTES_TO_A_WORD
lBytePosition = (lByteCount Mod BYTES_TO_A_WORD) * BITS_TO_A_BYTE
lWordArray(lWordCount) = lWordArray(lWordCount) Or LShift(Asc(Mid(sMessage, lByteCount + 1, 1)), lBytePosition)
lByteCount = lByteCount + 1
Loop
lWordCount = lByteCount \ BYTES_TO_A_WORD
lBytePosition = (lByteCount Mod BYTES_TO_A_WORD) * BITS_TO_A_BYTE
lWordArray(lWordCount) = lWordArray(lWordCount) Or LShift(&H80, lBytePosition)
lWordArray(lNumberOfWords - 2) = LShift(lMessageLength, 3)
lWordArray(lNumberOfWords - 1) = RShift(lMessageLength, 29)
ConvertToWordArray = lWordArray
End Function
Function WordToHex(lValue)
Dim lByte
Dim lCount
For lCount = 0 To 3
lByte = RShift(lValue, lCount * BITS_TO_A_BYTE) And m_lOnBits(BITS_TO_A_BYTE - 1)
WordToHex = WordToHex & Right("0" & Hex(lByte), 2)
Next
End Function
Function str2binl(str)
Dim nblk
nblk = ( RShift((Len(str) + 8), 6) ) + 1 ' number of 16-word blocks
Dim blks()
ReDim blks(nblk*16 - 1)
Dim x
For x=0 To nblk * 16 - 1
blks(x) = 0
Next
Dim arIdx
For x = 0 To Len(str)-1
arIdx = RShift(x,2)
blks(arIdx) = blks(arIdx) Or LShift(Asc(CStr(Mid(str,x+1,1))) And &hFF, ((x Mod 4) * 8))
Next
blks(RShift(x,2)) = blks(RShift(x,2)) Or LShift(&h80, ((x Mod 4) * 8))
blks(nblk*16-2) = Len(str) * 8
str2binl = blks
End Function
Function bytarray2binl(barray)
Dim nblk
nblk = RShift((UBound(barray) + 8), 6) + 1 ' number of 16-word blocks
Dim blks()
Redim blks(nblk*16 - 1)
Dim x
For x = 0 To nblk*16 - 1
blks(x) = 0
Next
Dim arIdx
For x = 0 To UBound(barray)
arIdx = RShift(x,2)
blks(arIdx) = blks(arIdx) Or LShift( barray(x) And &hFF, (x Mod 4) * 8)
Next
blks(RShift(x,2)) = blks(RShift(x,2)) Or LShift(&h80, ((x Mod 4) * 8))
blks(nblk*16-2) = (UBound(barray)+1) * 8
内容版权声明:除非注明,否则皆为本站原创文章。