Arthur Pires wrote:
> hi guys i need the string of a md5 digest
> (something like "9e107d9d372bb6826bd81d3542a419d6"),
> im trying this way, but it is not working right
>
> function LCStrMD5(const str: string): string;
> const
> Digits: array[0..15] of Char =
> ('0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f');
> var
> i: Integer;
> begin
> Result := MD5(str);
> for i := 1 to 16 do
> Result := Result + Digits[Byte(Result[i]) shr 4] +
> Digits[Byte(Result[i]) and $f];
> Result := AnsiLowerCase(Result);
> end;
>
>
> someone can help me?
>
What does "Not working right" mean? What output do you get? What output
do you expect? At the moment you are appending the hex version of the
MD5 to the MD5, instead of replacing it. The call to AnsiLowerCase is
superfluous.
function LCStrMD5(const str: string): string;
const
Digits: array[0..15] of Char =
('0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f');
var
i: Integer; m: String;
begin
m := MD5(str);
Result:='';
for i := 1 to 16 do
Result := Result + Digits[Byte(m[i]) shr 4] +
Digits[Byte(m[i]) and $f];
end;
Does MD5 already produce a hex-encoded string? Are you trying to encode
as hex twice?
Cheers,
Nicholas Sherlock
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
synalist-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/synalist-public