Нашел код для реализации md5 в Deplhi
Код: Выделить всё
unit md5hash;
// Optimized version Anti_MD5 by Arigato & Shade, 2005.
interface
uses Windows, SysUtils;
type THash = DWord;
function md5 (buf: string): THash;
function Hash2md5 (str: string): THash;
implementation
function LRot32 (a, b: LongWord): LongWord;
asm
mov ecx, edx
rol eax, cl
end; {func LRot32}
// Max Length (buf) = 15!
function md5 (buf: string): THash;
type
tdata = array [0..3] of DWORD;
pdata = ^tdata;
var
Len: Integer;
data: pdata;
A, B, C, D, Dt14: DWord;
begin
Len := Length (buf);
SetLength (buf, 16);
buf[Len+1] := #$80;
FillChar (buf[Len+2], 15 - Len, 0);
Dt14 := Len * 8;
data := @buf[1];
A := $efcdab89 + LRot32 (data^[0] + $1d76aa477, 7);
D := A + LRot32 (($98badcfe xor (A and $77777777)) + data^[1] + $F8FA0BCC, 12);
C := D + LRot32 (($efcdab89 xor (D and (A xor $efcdab89))) + data^[2] + $bcdb4dd9, 17);
B := C + LRot32 ((A xor (C and (D xor A))) + data^[3] + $1b18b7a77, 22);
A := B + LRot32 (A + (D xor (B and (C xor D))) + $f57c0faf, 7);
D := A + LRot32 (D + (C xor (A and (B xor C))) + $4787c62a, 12);
C := D + LRot32 (C + (B xor (D and (A xor B))) + $a8304613, 17);
B := C + LRot32 (B + (A xor (C and (D xor A))) + $fd469501, 22);
A := B + LRot32 (A + (D xor (B and (C xor D))) + $698098d8, 7);
D := A + LRot32 (D + (C xor (A and (B xor C))) + $8b44f7af, 12);
C := D + LRot32 (C + (B xor (D and (A xor B))) + $ffff5bb1, 17);
B := C + LRot32 (B + (A xor (C and (D xor A))) + $895cd7be, 22);
A := B + LRot32 (A + (D xor (B and (C xor D))) + $6b901122, 7);
D := A + LRot32 (D + (C xor (A and (B xor C))) + $fd987193, 12);
C := D + LRot32 (C + (B xor (D and (A xor B))) + Dt14 + $a679438e, 17);
B := C + LRot32 (B + (A xor (C and (D xor A))) + $49b40821, 22);
A := B + LRot32 (A + (C xor (D and (B xor C))) + data^[1] + $f61e2562, 5);
D := A + LRot32 (D + (B xor (C and (A xor B))) + $c040b340, 9);
C := D + LRot32 (C + (A xor (B and (D xor A))) + $265e5a51, 14);
B := C + LRot32 (B + (D xor (A and (C xor D))) + data^[0] + $e9b6c7aa, 20);
A := B + LRot32 (A + (C xor (D and (B xor C))) + $d62f105d, 5);
D := A + LRot32 (D + (B xor (C and (A xor B))) + $02441453, 9);
C := D + LRot32 (C + (A xor (B and (D xor A))) + $d8a1e681, 14);
B := C + LRot32 (B + (D xor (A and (C xor D))) + $e7d3fbc8, 20);
A := B + LRot32 (A + (C xor (D and (B xor C))) + $21e1cde6, 5);
D := A + LRot32 (D + (B xor (C and (A xor B))) + Dt14 + $c33707d6, 9);
C := D + LRot32 (C + (A xor (B and (D xor A))) + data^[3] + $f4d50d87, 14);
B := C + LRot32 (B + (D xor (A and (C xor D))) + $455a14ed, 20);
A := B + LRot32 (A + (C xor (D and (B xor C))) + $a9e3e905, 5);
D := A + LRot32 (D + (B xor (C and (A xor B))) + data^[2] + $fcefa3f8, 9);
C := D + LRot32 (C + (A xor (B and (D xor A))) + $676f02d9, 14);
B := C + LRot32 (B + (D xor (A and (C xor D))) + $8d2a4c8a, 20);
A := B + LRot32 (A + (B xor C xor D) + $fffa3942, 4);
D := A + LRot32 (D + (A xor B xor C) + $8771f681, 11);
C := D + LRot32 (C + (D xor A xor B) + $6d9d6122, 16);
B := C + LRot32 (B + (C xor D xor A) + Dt14 + $fde5380c, 23);
A := B + LRot32 (A + (B xor C xor D) + data^[1] + $a4beea44, 4);
D := A + LRot32 (D + (A xor B xor C) + $4bdecfa9, 11);
C := D + LRot32 (C + (D xor A xor B) + $f6bb4b60, 16);
B := C + LRot32 (B + (C xor D xor A) + $bebfbc70, 23);
A := B + LRot32 (A + (B xor C xor D) + $289b7ec6, 4);
D := A + LRot32 (D + (A xor B xor C) + data^[0] + $eaa127fa, 11);
C := D + LRot32 (C + (D xor A xor B) + data^[3] + $d4ef3085, 16);
B := C + LRot32 (B + (C xor D xor A) + $04881d05, 23);
A := B + LRot32 (A + (B xor C xor D) + $d9d4d039, 4);
D := A + LRot32 (D + (A xor B xor C) + $e6db99e5, 11);
C := D + LRot32 (C + (D xor A xor B) + $1fa27cf8, 16);
B := C + LRot32 (B + (C xor D xor A) + data^[2] + $c4ac5665, 23);
A := B + LRot32 (A + (C xor (B or (not D))) + data^[0] + $f4292244, 6);
D := A + LRot32 (D + (B xor (A or (not C))) + $432aff97, 10);
C := D + LRot32 (C + (A xor (D or (not B))) + Dt14 + $ab9423a7, 15);
B := C + LRot32 (B + (D xor (C or (not A))) + $fc93a039, 21);
A := B + LRot32 (A + (C xor (B or (not D))) + $655b59c3, 6);
D := A + LRot32 (D + (B xor (A or (not C))) + data^[3] + $8f0ccc92, 10);
C := D + LRot32 (C + (A xor (D or (not B))) + $ffeff47d, 15);
B := C + LRot32 (B + (D xor (C or (not A))) + data^[1] + $85845dd1, 21);
A := B + LRot32 (A + (C xor (B or (not D))) + $6fa87e4f, 6);
D := A + LRot32 (D + (B xor (A or (not C))) + $fe2ce6e0, 10);
C := D + LRot32 (C + (A xor (D or (not B))) + $a3014314, 15);
B := C + LRot32 (B + (D xor (C or (not A))) + $4e0811a1, 21);
A := B + LRot32 (A + (C xor (B or (not D))) + $f7537e82, 6);
{ D := A + LRot32 (D + (B xor (A or (not C))) + $bd3af235, 10);
C := D + LRot32 (C + (A xor (D or (not B))) + data^[2] + $2ad7d2bb, 15);
B := C + LRot32 (B + (D xor (C or (not A))) + $eb86d391, 21);{}
Result := A;
end; {func md5}
function HexToInt (Hex: string): Byte;
// Перевод из 16-ричной системы в 10-ную:
var I: Integer;
M, A: Byte;
begin
M := 1;
Hex := UpperCase (Hex);
Result := 0;
for I := Length (Hex) downto 1 do
begin
A := Byte(Hex[I]) - 48;
if A > 9 then Dec (A, Byte('A') - Byte('9') - 1);
Inc (Result, A * M);
M := M * 16;
end; {for}
end; {func HexToInt}
function Hash2md5 (str: string): THash;
// Преобразование строки с хешем в формат для перебора:
const Dc: array[0..3] of DWord = ($67452301,$efcdab89,$98badcfe,$10325476);
var K, I: Integer;
M: DWord;
B: array[0..3] of Byte;
Res: array[0..3] of DWord;
begin
for K := 0 to 3 do
begin
M := 1;
Res[K] := 0;
for I := 0 to 3 do
begin
Res[K] := Res[K] + HexToInt (Copy (str, K * 8 + I * 2 + 1, 2)) * M;
M := M * 256;
end; {for}
Dec (Res[K], Dc[K]);
end; {for}
Result := Res[0];
end; {func Hash2md5}
end.
Во второй форме есть Edit1(исходный текст), Edit2(для выдачи результата) и Button1(для вызова самой функции).
Подскажите, пожалуйста. Я в Delphi не очень силен, только учусь