高分求助,delphi转BCB(40行左右)
最近在网络上找了个MD5的算法,不过是delphi写的,我不会delphi,只懂一些BCB
麻烦某个混编的强人帮小弟转一下。谢谢
function GetCommandLine(QQNum, QQPw: string; QQState: integer): string;
type
TempChar = array[0..15] of char;
var
md5: TIdHashMessageDigest5;
begin
md5 := TIdHashMessageDigest5.Create;
result := ' /START QQUIN: ' + QQNum + ' PWDHASH: ' + Base64(TempChar(md5.HashValue(QQPw))) + ' /STAT: ' + IntToStr(QQState);
md5.Free;
end;
function Base64(Src: string): string;
const
DataSet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/ ';
var
i, ModLen: integer;
Current: string;
Buf: array[1..3] of Byte;
NewBuf: array[1..4] of Byte;
begin
result := ' ';
if Src = ' ' then
exit;
ModLen := Length(Src) mod 3;
while Length(Src) > 0 do
begin
FillChar(Buf, 3, #0);
Current := Copy(Src, 1, 3);
Src := Copy(Src, 4, Length(Src) - 3);
for i := 1 to 3 do
Buf[i] := Ord(Current[i]);
NewBuf[1] := Buf[1] shr 2;
NewBuf[2] := (Buf[1] shl 6 shr 2 or Buf[2] shr 4) and $3F;
NewBuf[3] := (Buf[2] shl 4 shr 2 or Buf[3] shr 6) and $3F;
NewBuf[4] := Buf[3] and $3F;
for i := 1 to 4 do
result := result + DataSet[NewBuf[i] + 1];
end;
if ModLen > = 1 then
result[Length(result)] := '= ';
if ModLen = 1 then
result[Length(result) - 1] := '= ';
end;
一共就两个函数,谢谢帮转一下,我不是自己懒,只是有许多地方看不懂,自己弄了两个晚上都没弄出来。
原文出处:http://hi.baidu.com/chixuelang/blog/item/9f07a482c7e7aa91f603a69d.html
[解决办法]
String GetCommandLine( String QQNum, String QQPw, int QQState )
{
char TempChar[16];
TIdHashMessageDigest5 *md5 = new TIdHashMessageDigest5(); //
String Ret = " /START QQUIN: " + QQNum + " PWDHASH: " + Base64(TempChar(md5.HashValue(QQPw))) + " /STAT: " + IntToStr(QQState);
delete md5;
}
[解决办法]
这个是md5?跟我看到的差别太大了
建议直接使用pas文件,编译出hpp文件,然后include就行了
要不直接找vc的好了,又不是没有,何必装呢
[解决办法]
Indy控件妖哥网站(www.ccrun.com)有下载
[解决办法]
给你个我用的C++代码的MD5实现
.h文件
/******************************************************************************
* Copyright (C) 2000 by Robert Hubley. *
* All rights reserved. *
* *
* This software is provided ``AS IS ' ' and any express or implied *
* warranties, including, but not limited to, the implied warranties of *
* merchantability and fitness for a particular purpose, are disclaimed. *
* In no event shall the authors be liable for any direct, indirect, *
* incidental, special, exemplary, or consequential damages (including, but *
* not limited to, procurement of substitute goods or services; loss of use, *
* data, or profits; or business interruption) however caused and on any *
* theory of liability, whether in contract, strict liability, or tort *
* (including negligence or otherwise) arising in any way out of the use of *
* this software, even if advised of the possibility of such damage. *
* *
******************************************************************************
MD5.H - header file for MD5C.C
Port to Win32 DLL by Robert Hubley 1/5/2000
Original Copyright:
Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
rights reserved.
License to copy and use this software is granted provided that it
is identified as the "RSA Data Security, Inc. MD5 Message-Digest
Algorithm " in all material mentioning or referencing this software
or this function.
License is also granted to make and use derivative works provided
that such works are identified as "derived from the RSA Data
Security, Inc. MD5 Message-Digest Algorithm " in all material
mentioning or referencing the derived work.
RSA Data Security, Inc. makes no representations concerning either
the merchantability of this software or the suitability of this
software for any particular purpose. It is provided "as is "
without express or implied warranty of any kind.
These notices must be retained in any copies of any part of this
documentation and/or software.
*/
/******************************************************************************
* Copyright (C) 2000 by Robert Hubley. *
* All rights reserved. *
* *
* This software is provided ``AS IS ' ' and any express or implied *
* warranties, including, but not limited to, the implied warranties of *
* merchantability and fitness for a particular purpose, are disclaimed. *
* In no event shall the authors be liable for any direct, indirect, *
* incidental, special, exemplary, or consequential damages (including, but *
* not limited to, procurement of substitute goods or services; loss of use, *
* data, or profits; or business interruption) however caused and on any *
* theory of liability, whether in contract, strict liability, or tort *
* (including negligence or otherwise) arising in any way out of the use of *
* this software, even if advised of the possibility of such damage. *
* *
******************************************************************************
*/
/******************************************************************************
* 2002-4-18 Modified by Liguangyi. *
* struct MD5_CTX ==> class MD5_CTX. *
* Take off the Globals Functions *
******************************************************************************
*/
#ifndef _LGY_MD5_H
#define _LGY_MD5_H
/* MD5 Class. */
class MD5_CTX {
public:
MD5_CTX();
virtual ~MD5_CTX();
void MD5Update ( unsigned char *input, unsigned int inputLen);
void MD5Final (unsigned char digest[16]);
private:
unsigned long int state[4];/* state (ABCD) */
unsigned long int count[2];/* number of bits, modulo 2^64 (lsb first) */
unsigned char buffer[64]; /* input buffer */
unsigned char PADDING[64];/* What? */
private:
void MD5Init ();
void MD5Transform (unsigned long int state[4], unsigned char block[64]);
void MD5_memcpy (unsigned char* output, unsigned char* input,unsigned int len);
void Encode (unsigned char *output, unsigned long int *input,unsigned int len);
void Decode (unsigned long int *output, unsigned char *input, unsigned int len);
void MD5_memset (unsigned char* output,int value,unsigned int len);
};
#endif