标题:帮我 翻译成c++,然后封装,谢谢了
只看楼主
yizhiduxiu
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2005-12-26
 问题点数:0 回复次数:1 
帮我 翻译成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

搜索更多相关主题的帖子: 封装 翻译 
2005-12-27 11:25
zhzhiwei
Rank: 1
等 级:新手上路
帖 子:412
专家分:0
注 册:2005-9-8
得分:0 
虽然大家都很希望你把论坛当成家,,,,,
......不过很抱歉你跟你说,论坛不是你的家!!!

一只鹰其实不孤独,想另一只天鹅,才孤独.真正的孤独!!
2005-12-27 21:05



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-40170-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.141707 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved