AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

MD5 Länge einfügen als 64 Bit?

Ein Thema von fortuneNext · begonnen am 25. Feb 2009 · letzter Beitrag vom 5. Mär 2009
 
Benutzerbild von himitsu
himitsu

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
44.399 Beiträge
 
Delphi 12 Athens
 
#19

Re: MD5 Länge einfügen als 64 Bit?

  Alt 3. Mär 2009, 09:18
konnte jetzt nicht testen, ob's so geht, aber einige Fehler hab ich schonmal gefunden.

deine Zeilen auskommentiert, dann 'ne kleine Beschreibung dazu und darunter direkt den Fehler behoben

Delphi-Quellcode:
function TMD5.Crypt(text: string):string;
var
  r: array[0..63] of longword;
  k: array[0..63] of longword;
  i, x, y: longword;
  a, b, c, d: longword;
  h0, h1, h2, h3: longword;
  textlength: int64;
  block: string;
  w: array[0..15] of longword;
  f, g: longword;
  temp: longword;
begin
  r[0] := 7;
  r[1] := 12;
  r[2] := 17;
  r[3] := 22;
  r[4] := 7;
  r[5] := 12;
  r[6] := 17;
  r[7] := 22;
  r[8] := 7;
  r[9] := 12;
  r[10] := 17;
  r[11] := 22;
  r[12] := 7;
  r[13] := 12;
  r[14] := 17;
  r[15] := 22;

  r[16] := 5;
  r[17] := 9;
  r[18] := 14;
  r[19] := 20;
  r[20] := 5;
  r[21] := 9;
  r[22] := 14;
  r[23] := 20;
  r[24] := 5;
  r[25] := 9;
  r[26] := 14;
  r[27] := 20;
  r[28] := 5;
  r[29] := 9;
  r[30] := 14;
  r[31] := 20;

  r[32] := 4;
  r[33] := 11;
  r[34] := 16;
  r[35] := 23;
  r[36] := 4;
  r[37] := 11;
  r[38] := 16;
  r[39] := 23;
  r[40] := 4;
  r[41] := 11;
  r[42] := 16;
  r[43] := 23;
  r[44] := 4;
  r[45] := 11;
  r[46] := 16;
  r[47] := 23;

  r[48] := 6;
  r[49] := 10;
  r[50] := 15;
  r[51] := 21;
  r[52] := 6;
  r[53] := 10;
  r[54] := 15;
  r[55] := 21;
  r[56] := 6;
  r[57] := 10;
  r[58] := 15;
  r[59] := 21;
  r[60] := 6;
  r[61] := 10;
  r[62] := 15;
  r[63] := 21;

  for i := 0 to 63 do
  begin
    k[i] := floor(abs(sin(i + 1) * power(2, 32)));
  end;

  h0 := $67452301;
  h1 := $EFCDAB89;
  h2 := $98BADCFE;
  h3 := $10325476;

  textlength := length(text) * 8;
  text := text + #$80;
  while ((length(text) * 8) mod 512) <> 448 do
    text := text + #$00;
  text := text + Int64ToBinLength(textlength);

  for x := 1 to (length(text) * 8) div 512 do
  begin
    //block := copy(text, (512 div 8) * x, 512 div 8);
    /// (512 div 8) * x für x = 1 {startwert}
    /// (512 div 8) * 1 = 64 müßte aber 1 sein {1 = erstes Zeichen im String}
    block := copy(text, (512 div 8) * (x - 1) + 1, 512 div 8);
    ///for i := 0 to 15 do
    /// //move(block[i * 32 + 1], w, 32);
    /// move(block[i * (32 div 8) + 1], w[i], (32 div 8)); // du willtest doch wohl alles in
    ///oder gleich // die EINZELNEN w[i] reinkoppieren
    move(block[1], w, 512 div 8); // und die 32 waren wohl noch Bits

    a := h0;
    b := h1;
    c := h2;
    d := h3;

    for i := 0 to 63 do
    begin
      if (0 <= i) and (i <= 15) then
      begin
        f := (b and c) or ((not b) and d);
        g := i;
      end
      else if (16 <= i) and (i <= 31) then
      begin
        f := (b and d) or (c and (not d));
        g := (5*i + 1) mod 16;
      end
      else if (32 <= i) and (i <= 47) then
      begin
        f := b xor c xor d;
        g := (3*i + 5) mod 16;
      end
      else if (48 <= i) and (i <= 63) then
      begin
        f := c xor (b or (not d));
        g := (7*i) mod 16;
      end;

      temp := d;
      d := c; // dieze Zeile hattest'e vergessen
      c := b;
      // die lange Formel stimmt ^^
      b := ((a + f + k[i] + w[g]) shl (r[i])) or ((a + f + k[i] + w[g]) shr (32 - r[i])) + b;
      a := temp;
    end;

    h0 := h0 + a;
    h1 := h1 + b;
    h2 := h2 + c;
    h3 := h3 + d;

  end;

  Result := Format('$%.2x%.2x%.2x%.2x %.2x%.2x%.2x%.2x %.2x%.2x%.2x%.2x %.2x%.2x%.2x%.2x',
      [h0 shr 0 and $ff, h0 shr 8 and $ff, h0 shr 16 and $ff, h0 shr 24 and $ff,
       h1 shr 0 and $ff, h1 shr 8 and $ff, h1 shr 16 and $ff, h1 shr 24 and $ff,
       h2 shr 0 and $ff, h2 shr 8 and $ff, h2 shr 16 and $ff, h2 shr 24 and $ff,
       h3 shr 0 and $ff, h3 shr 8 and $ff, h3 shr 16 and $ff, h3 shr 24 and $ff]);

end;
Ein Therapeut entspricht 1024 Gigapeut.
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 03:50 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz