当前位置: 代码迷 >> C语言 >> 把vb代码翻译成c++代码然后用类封装是怎么回事?
  详细解决方案

把vb代码翻译成c++代码然后用类封装是怎么回事?

热度:233   发布时间:2005-12-27 10:39:00.0
把vb代码翻译成c++代码然后用类封装是怎么回事?

就是把以下代码用c++翻译然后用类封装
Option Strict On
Option Explicit On

Imports System.Security.Cryptography

Public Class MD5
Public Shared Function MD5Hash(ByVal str As String) As String

Dim len As Integer = util.StrLen(str)
Dim buf(len - 1), buf2() As Byte
Dim i, c As Integer

util.S2B(str, buf, str.Length())

Dim Crypto As New MD5CryptoServiceProvider()
buf2 = Crypto.ComputeHash(buf)

MD5Hash = ""
For i = 0 To buf2.Length - 1

c = CType((buf2(i) And &HF0) / 16, Integer)
If c < 10 Then
c += 48
Else
c += 87
End If
MD5Hash += Chr(c)

c = buf2(i) And &HF
If c < 10 Then
c += 48
Else
c += 87
End If
MD5Hash += Chr(c)

Next

End Function

End Class


Public Shared Sub S2B(ByVal str As String, ByRef buf As Byte(), ByVal len As Integer)

Dim i, p, ch As Integer

p = 0
For i = 0 To len - 1
ch = Asc(str.Chars(i))
If ch > 126 Or ch < 0 Then
buf(p) = CType((ch And &HFF00) / 256, Byte)
p += 1
buf(p) = CType(ch And &HFF, Byte)
Else
buf(p) = CType(ch, Byte)
End If
p += 1
Next
End Sub

搜索更多相关的解决方案: 封装  代码  翻译  

----------------解决方案--------------------------------------------------------
  相关解决方案