delphi md5



Автор Пользователь удален задал вопрос в разделе Компьютеры, Связь

Существуют ли в Delphi стандартные хэш-функции? Например, как MD5 в PHP. и получил лучший ответ

Ответ от Andrew Tishkin[гуру]
Вот модуль, вычисляющий MD5 в Delphi. Полностью могу прислать по почте. Если надо - пиши ( :-)))) За 10 баллов :-)))))Здесь размещено ТОЛЬКО НАЧАЛО юнита! Полностью не вместился.. . Так что пиши мне-----------------------------unit md5;interfaceuses Windows, SysUtils, Classes;type { Тип TMD5Digest используется для получения результата функций вычисления хеш-суммы. Содержимое записи можно использовать как набор из 4 целых чисел, или как массив из 16 байт } PMD5Digest = ^TMD5Digest; TMD5Digest = record case Integer of 0: (A, B, C, D: LongInt); 1: (v: array[0..15] of Byte); end; // вычисление хеш-суммы для строкиfunction MD5String(const S: string): TMD5Digest;// вычисление хеш-суммы для файлаfunction MD5File(const FileName: string): TMD5Digest;// вычисление хеш-суммы для содержиого потока Streamfunction MD5Stream(const Stream: TStream): TMD5Digest;// вычисление хеш-суммы для произвольного буфераfunction MD5Buffer(const Buffer; Size: Integer): TMD5Digest;// преобразование хеш-суммы в строку из шестнадцатеричных цифрfunction MD5DigestToStr(const Digest: TMD5Digest): string;// сравнение двух хеш-суммfunction MD5DigestCompare(const Digest1, Digest2: TMD5Digest): Boolean;implementation{Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. Allrights reserved.License to copy and use this software is granted provided that itis identified as the "RSA Data Security, Inc. MD5 Message-DigestAlgorithm" in all material mentioning or referencing this softwareor this function.License is also granted to make and use derivative works providedthat such works are identified as "derived from the RSA DataSecurity, Inc. MD5 Message-Digest Algorithm" in all materialmentioning or referencing the derived work.RSA Data Security, Inc. makes no representations concerning eitherthe merchantability of this software or the suitability of thissoftware 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 thisdocumentation and/or software.}type UINT4 = LongWord; PArray4UINT4 = ^TArray4UINT4; TArray4UINT4 = array[0..3] of UINT4; PArray2UINT4 = ^TArray2UINT4; TArray2UINT4 = array[0..1] of UINT4; PArray16Byte = ^TArray16Byte; TArray16Byte = array[0..15] of Byte; PArray64Byte = ^TArray64Byte; TArray64Byte = array[0..63] of Byte; PByteArray = ^TByteArray; TByteArray = array[0..0] of Byte; PUINT4Array = ^TUINT4Array; TUINT4Array = array[0..0] of UINT4; PMD5Context = ^TMD5Context; TMD5Context = record state: TArray4UINT4; count: TArray2UINT4; buffer: TArray64Byte; end;const S11 = 7; S12 = 12; S13 = 17; S14 = 22; S21 = 5; S22 = 9; S23 = 14; S24 = 20; S31 = 4; S32 = 11; S33 = 16; S34 = 23; S41 = 6; S42 = 10; S43 = 15; S44 = 21;var Padding: TArray64Byte = ($80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);function _F(x, y, z: UINT4): UINT4;begin Result := (((x) and (y)) or ((not x) and (z)));end;function _G(x, y, z: UINT4): UINT4;begin Result := (((x) and (z)) or ((y) and (not z)));end;function _H(x, y, z: UINT4): UINT4;begin Result := ((x) xor (y) xor (z));end;function _I(x, y, z: UINT4): UINT4;begin Result := ((y) xor ((x) or (not z)));end;function ROTATE_LEFT(x, n: UINT4): UINT4;begin Result := (((x) shl (n)) or ((x) shr (32 - (n))));end;procedure FF(var a: UINT4; b, c, d, x, s, ac: UINT4);begin a := a + _F(b, c, d) + x + ac; a := ROTATE_LEFT(a, s); a := a + b;end;procedure GG(var a: UINT4; b, c, d, x, s, ac: UINT4);begin a := a + _G(b, c, d) + x + ac; a := ROTATE_LEFT(a, s);

Ответ от GambiT[гуру]
Стандартных нет, но вот тебе функция в помощь.
Передаешь строку, получаеш md5 строки

Function md5(s:string):string;

{©Drkb v.3(2007): ссылка,
®Vit (Vitaly Nevzorov) - nevzorov@yahoo.com}

var a:array[0..15] of byte;
i:integer;

LenHi, LenLo: longword;
Index: DWord;
HashBuffer: array[0..63] of byte;
CurrentHash: array[0..3] of DWord;

procedure Burn;
begin
LenHi:= 0; LenLo:= 0;
Index:= 0;
FillChar(HashBuffer,Sizeof(HashBuffer),0);
FillChar(CurrentHash,Sizeof(CurrentHash),0);
end;

procedure Init;
begin
Burn;
CurrentHash[0]:= $67452301;
CurrentHash[1]:= $efcdab89;
CurrentHash[2]:= $98badcfe;
CurrentHash[3]:= $10325476;
end;

function LRot32(a, b: longword): longword;
begin
Result:= (a shl b) or (a shr (32-b));
end;

procedure Compress;
var
Data: array[0..15] of dword;
A, B, C, D: dword;
begin
Move(HashBuffer,Data,Sizeof(Data));
A:= CurrentHash[0];
B:= CurrentHash[1];
C:= CurrentHash[2];
D:= CurrentHash[3];

A:= B + LRot32(A + (D xor (B and (C xor D))) + Data[ 0] + $d76aa478,7);
D:= A + LRot32(D + (C xor (A and (B xor C))) + Data[ 1] + $e8c7b756,12);
C:= D + LRot32(C + (B xor (D and (A xor B))) + Data[ 2] + $242070db,17);
B:= C + LRot32(B + (A xor (C and (D xor A))) + Data[ 3] + $c1bdceee,22);
A:= B + LRot32(A + (D xor (B and (C xor D))) + Data[ 4] + $f57c0faf,7);
D:= A + LRot32(D + (C xor (A and (B xor C))) + Data[ 5] + $4787c62a,12);
C:= D + LRot32(C + (B xor (D and (A xor B))) + Data[ 6] + $a8304613,17);
B:= C + LRot32(B + (A xor (C and (D xor A))) + Data[ 7] + $fd469501,22);
A:= B + LRot32(A + (D xor (B and (C xor D))) + Data[ 8] + $698098d8,7);
D:= A + LRot32(D + (C xor (A and (B xor C))) + Data[ 9] + $8b44f7af,12);
C:= D + LRot32(C + (B xor (D and (A xor B))) + Data[10] + $ffff5bb1,17);
B:= C + LRot32(B + (A xor (C and (D xor A))) + Data[11] + $895cd7be,22);
A:= B + LRot32(A + (D xor (B and (C xor D))) + Data[12] + $6b901122,7);
D:= A + LRot32(D + (C xor (A and (B xor C))) + Data[13] + $fd987193,12);
C:= D + LRot32(C + (B xor (D and (A xor B))) + Data[14] + $a679438e,17);
B:= C + LRot32(B + (A xor (C and (D xor A))) + Data[15] + $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))) + Data[ 6] + $c040b340,9);
C:= D + LRot32(C + (A xor (B and (D xor A))) + Data[11] + $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))) + Data[ 5] + $d62f105d,5);
D:= A + LRot32(D + (B xor (C and (A xor B))) + Data[10] + $02441453,9);
C:= D + LRot32(C + (A xor (B and (D xor A))) + Data[15] + $d8a1e681,14);
B:= C + LRot32(B + (D xor (A and (C xor D))) + Data[ 4] + $e7d3fbc8,20);
A:= B + LRot32(A + (C xor (D and (B xor C))) + Data[ 9] + $21e1cde6,5);
D:= A + LRot32(D + (B xor (C and (A xor B))) + Data[14] + $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))) + Data[ 8] + $455a14ed,20);
A:= B + LRot32(A + (C xor (D and (B xor C))) + Data[13] + $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))) + Data[ 7] + $676f02d9,14);
B:= C + LRot32(B + (D xor (A and (C xor D))) + Data[12] + $8d2a4c8a,20);

A:= B + LRot32(A + (B xor C xor D) + Data[ 5] + $fffa3942,4);
D:= A + LRot32(D + (A xor B xor C) + Data[ 8] + $8771f681,11);
C:= D + LRot32(C + (D xor A xor B) + Data[11] + $6d9d6122,16);
B:= C + LRot32(B + (C xor D xor A) + Data[14] + $fde5380c,23);
A:= B + LRot32(A + (B xor C xor D) + Data[ 1] + $a4beea44,4);
D:= A + LRot32(D + (A xor B xor C) + Data[ 4] + $4bdecfa9,11);
C:= D + LRot32(C + (D xor A

Ответ от 3 ответа[гуру]
Привет! Вот подборка тем с ответами на Ваш вопрос: Существуют ли в Delphi стандартные хэш-функции? Например, как MD5 в PHP.
спросили в Другое
что означает число 741
нечетное целое положительное трехзначное число, кратно 3, в сумме своей составляет тоже 3,
подробнее...
спросили в Wing Commander
Функция ReadFile Делфи, корректно ли она работает с файлами больше 4 Гб
Сложно сказать) Попробуйте прочитать ею последние 10-20 байт и сравнить с тем, что показывает
подробнее...
 

Ответить на вопрос:

Имя*

E-mail:*

Текст ответа:*
Проверочный код(введите 22):*