Advertisement
Gov_777

md5_64

Mar 9th, 2016
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 7.48 KB | None | 0 0
  1. источник http://www.cyberforum.ru/blogs/178692/blog564.html
  2. протестирован на Делфи - хе10 seattle
  3.  
  4. unit Umd5;
  5. interface
  6. uses Windows, SysUtils;
  7. function md5UTF8 (buf: UTF8String): AnsiString;
  8. function md5 (buf: AnsiString): AnsiString;
  9. implementation
  10. type
  11.   tdata = array [0..15] of DWORD;
  12.   tcur = array[0..3] of DWord;
  13. var HEX: array[Word] of AnsiString;
  14. function LRot32 (a, b: LongWord): LongWord;
  15. asm
  16.   mov  ecx, edx
  17.   rol  eax, cl
  18. end;
  19.  
  20. procedure md5calculate(var A, B, C, D: DWord; var data: tdata; var CurrentHash: tcur);
  21. begin
  22.   CurrentHash[0] := $67452301;
  23.   CurrentHash[1] := $efcdab89;
  24.   CurrentHash[2] := $98badcfe;
  25.   CurrentHash[3] := $10325476;
  26.   A := CurrentHash[0];
  27.   B := CurrentHash[1];
  28.   C := CurrentHash[2];
  29.   D := CurrentHash[3];
  30.   A := B + LRot32 (A + (D xor (B and (C xor D))) + data[ 0] + $d76aa478, 7);
  31.   D := A + LRot32 (D + (C xor (A and (B xor C))) + data[ 1] + $e8c7b756, 12);
  32.   C := D + LRot32 (C + (B xor (D and (A xor B))) + data[ 2] + $242070db, 17);
  33.   B := C + LRot32 (B + (A xor (C and (D xor A))) + data[ 3] + $c1bdceee, 22);
  34.   A := B + LRot32 (A + (D xor (B and (C xor D))) + data[ 4] + $f57c0faf, 7);
  35.   D := A + LRot32 (D + (C xor (A and (B xor C))) + data[ 5] + $4787c62a, 12);
  36.   C := D + LRot32 (C + (B xor (D and (A xor B))) + data[ 6] + $a8304613, 17);
  37.   B := C + LRot32 (B + (A xor (C and (D xor A))) + data[ 7] + $fd469501, 22);
  38.   A := B + LRot32 (A + (D xor (B and (C xor D))) + data[ 8] + $698098d8, 7);
  39.   D := A + LRot32 (D + (C xor (A and (B xor C))) + data[ 9] + $8b44f7af, 12);
  40.   C := D + LRot32 (C + (B xor (D and (A xor B))) + data[10] + $ffff5bb1, 17);
  41.   B := C + LRot32 (B + (A xor (C and (D xor A))) + data[11] + $895cd7be, 22);
  42.   A := B + LRot32 (A + (D xor (B and (C xor D))) + data[12] + $6b901122, 7);
  43.   D := A + LRot32 (D + (C xor (A and (B xor C))) + data[13] + $fd987193, 12);
  44.   C := D + LRot32 (C + (B xor (D and (A xor B))) + data[14] + $a679438e, 17);
  45.   B := C + LRot32 (B + (A xor (C and (D xor A))) + data[15] + $49b40821, 22);
  46.   A := B + LRot32 (A + (C xor (D and (B xor C))) + data[ 1] + $f61e2562, 5);
  47.   D := A + LRot32 (D + (B xor (C and (A xor B))) + data[ 6] + $c040b340, 9);
  48.   C := D + LRot32 (C + (A xor (B and (D xor A))) + data[11] + $265e5a51, 14);
  49.   B := C + LRot32 (B + (D xor (A and (C xor D))) + data[ 0] + $e9b6c7aa, 20);
  50.   A := B + LRot32 (A + (C xor (D and (B xor C))) + data[ 5] + $d62f105d, 5);
  51.   D := A + LRot32 (D + (B xor (C and (A xor B))) + data[10] + $02441453, 9);
  52.   C := D + LRot32 (C + (A xor (B and (D xor A))) + data[15] + $d8a1e681, 14);
  53.   B := C + LRot32 (B + (D xor (A and (C xor D))) + data[ 4] + $e7d3fbc8, 20);
  54.   A := B + LRot32 (A + (C xor (D and (B xor C))) + data[ 9] + $21e1cde6, 5);
  55.   D := A + LRot32 (D + (B xor (C and (A xor B))) + data[14] + $c33707d6, 9);
  56.   C := D + LRot32 (C + (A xor (B and (D xor A))) + data[ 3] + $f4d50d87, 14);
  57.   B := C + LRot32 (B + (D xor (A and (C xor D))) + data[ 8] + $455a14ed, 20);
  58.   A := B + LRot32 (A + (C xor (D and (B xor C))) + data[13] + $a9e3e905, 5);
  59.   D := A + LRot32 (D + (B xor (C and (A xor B))) + data[ 2] + $fcefa3f8, 9);
  60.   C := D + LRot32 (C + (A xor (B and (D xor A))) + data[ 7] + $676f02d9, 14);
  61.   B := C + LRot32 (B + (D xor (A and (C xor D))) + data[12] + $8d2a4c8a, 20);
  62.   A := B + LRot32 (A + (B xor C xor D) + data[ 5] + $fffa3942, 4);
  63.   D := A + LRot32 (D + (A xor B xor C) + data[ 8] + $8771f681, 11);
  64.   C := D + LRot32 (C + (D xor A xor B) + data[11] + $6d9d6122, 16);
  65.   B := C + LRot32 (B + (C xor D xor A) + data[14] + $fde5380c, 23);
  66.   A := B + LRot32 (A + (B xor C xor D) + data[ 1] + $a4beea44, 4);
  67.   D := A + LRot32 (D + (A xor B xor C) + data[ 4] + $4bdecfa9, 11);
  68.   C := D + LRot32 (C + (D xor A xor B) + data[ 7] + $f6bb4b60, 16);
  69.   B := C + LRot32 (B + (C xor D xor A) + data[10] + $bebfbc70, 23);
  70.   A := B + LRot32 (A + (B xor C xor D) + data[13] + $289b7ec6, 4);
  71.   D := A + LRot32 (D + (A xor B xor C) + data[ 0] + $eaa127fa, 11);
  72.   C := D + LRot32 (C + (D xor A xor B) + data[ 3] + $d4ef3085, 16);
  73.   B := C + LRot32 (B + (C xor D xor A) + data[ 6] + $04881d05, 23);
  74.   A := B + LRot32 (A + (B xor C xor D) + data[ 9] + $d9d4d039, 4);
  75.   D := A + LRot32 (D + (A xor B xor C) + data[12] + $e6db99e5, 11);
  76.   C := D + LRot32 (C + (D xor A xor B) + data[15] + $1fa27cf8, 16);
  77.   B := C + LRot32 (B + (C xor D xor A) + data[ 2] + $c4ac5665, 23);
  78.   A := B + LRot32 (A + (C xor (B or (not D))) + data[ 0] + $f4292244, 6);
  79.   D := A + LRot32 (D + (B xor (A or (not C))) + data[ 7] + $432aff97, 10);
  80.   C := D + LRot32 (C + (A xor (D or (not B))) + data[14] + $ab9423a7, 15);
  81.   B := C + LRot32 (B + (D xor (C or (not A))) + data[ 5] + $fc93a039, 21);
  82.   A := B + LRot32 (A + (C xor (B or (not D))) + data[12] + $655b59c3, 6);
  83.   D := A + LRot32 (D + (B xor (A or (not C))) + data[ 3] + $8f0ccc92, 10);
  84.   C := D + LRot32 (C + (A xor (D or (not B))) + data[10] + $ffeff47d, 15);
  85.   B := C + LRot32 (B + (D xor (C or (not A))) + data[ 1] + $85845dd1, 21);
  86.   A := B + LRot32 (A + (C xor (B or (not D))) + data[ 8] + $6fa87e4f, 6);
  87.   D := A + LRot32 (D + (B xor (A or (not C))) + data[15] + $fe2ce6e0, 10);
  88.   C := D + LRot32 (C + (A xor (D or (not B))) + data[ 6] + $a3014314, 15);
  89.   B := C + LRot32 (B + (D xor (C or (not A))) + data[13] + $4e0811a1, 21);
  90.   A := B + LRot32 (A + (C xor (B or (not D))) + data[ 4] + $f7537e82, 6);
  91.   D := A + LRot32 (D + (B xor (A or (not C))) + data[11] + $bd3af235, 10);
  92.   C := D + LRot32 (C + (A xor (D or (not B))) + data[ 2] + $2ad7d2bb, 15);
  93.   B := C + LRot32 (B + (D xor (C or (not A))) + data[ 9] + $eb86d391, 21);
  94.   Inc (CurrentHash[0], A);
  95.   Inc (CurrentHash[1], B);
  96.   Inc (CurrentHash[2], C);
  97.   Inc (CurrentHash[3], D);
  98. end;
  99.  
  100. function md5 (buf: AnsiString): AnsiString;
  101. type
  102.   pint = ^Integer;
  103.   tbyte = array [0..15] of byte;
  104.   pdata = ^tdata;
  105.   pbyte = ^tbyte;
  106. var
  107.   i, Len: Integer;
  108.   data: pdata;
  109.   CurrentHash: tcur;
  110.   P: array[0..7] of Word absolute CurrentHash;
  111.   A, B, C, D: DWord;
  112. begin
  113.   Len := Length (buf);
  114.   SetLength (buf, 64);
  115.   buf[Len+1] := #$80;
  116.   FillChar (buf[Len+2], 63 - Len, 0);
  117.   pint (@buf[57])^ := Len * 8;
  118.   data := addr (buf[1]);
  119.   md5calculate(a,b,c,d,data^,CurrentHash);
  120.   Result := HEX[P[0]];
  121.   for i := 1 to 7 do
  122.     Result := Concat (Result, HEX[P[i]]);
  123. end;
  124.  
  125. function md5UTF8 (buf: UTF8String): AnsiString;
  126. type
  127.   pint = ^Integer;
  128.   tbyte = array [0..15] of byte;
  129.   pdata = ^tdata;
  130.   pbyte = ^tbyte;
  131. var
  132.   i, Len: Integer;
  133.   data: pdata;
  134.   CurrentHash: tcur;
  135.   P: array[0..7] of Word absolute CurrentHash;
  136.   A, B, C, D: DWord;
  137. begin
  138.   {$IFDEF UNICODE}{$ELSE}
  139.   buf:= UTF8ToAnsi(buf);
  140.   {$EndIf}
  141.   Len := Length (buf);
  142.   SetLength (buf, 64);
  143.   buf[Len+1] := #$80;
  144.   FillChar (buf[Len+2], 63 - Len, 0);
  145.   pint (@buf[57])^ := Len * 8;
  146.  
  147.   data := addr (buf[1]);
  148.  
  149.   md5calculate(a,b,c,d,data^,CurrentHash);
  150.  
  151.   Result := HEX[P[0]];
  152.   for i := 1 to 7 do
  153.     Result := Concat (Result, HEX[P[i]]);
  154. end;
  155.  
  156. var DEC, Tmp: Integer;
  157.     LH: string;
  158.  
  159. initialization
  160.  
  161. for DEC := 0 to $ffff do
  162. begin
  163.   Tmp := DEC and $ff;
  164.   LH := IntToHex (Tmp, 2);
  165.   Tmp := DEC shr 8;
  166.   HEX[DEC] := Concat (LH, IntToHex (Tmp, 2));
  167. end;
  168. end.
  169. //////////////////////////////////////////////////
  170. //для брута с пост запросом с кириллическим паролем
  171. {применение}
  172. edit1.Text:=LowerCase(md5UTF8(trim(memo1.Text)));//получить хеш с кириллической строки совпадающий с тем, что дает php
  173. edit1.Text:=LowerCase(md5(trim(memo1.Text)));//другой вариант
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement