Thema: Delphi Mini-SHA1

Einzelnen Beitrag anzeigen

SittingDuck

Registriert seit: 11. Jan 2006
Ort: Leverkusen
159 Beiträge
 
Delphi 2010 Professional
 
#2

AW: Mini-SHA1

  Alt 15. Okt 2011, 17:17
Hallo zusammen ...

Ich wollte die Routine von himitsu 'mal eben' umstellen auf die Ausgabe im Hex-Format. In der Bit-Schiebe-Routine stimmt aber was nicht. Dem entsprechend ist das Ergebnis dann leider auch falsch. Ich habe den Base64 Teil einfach mal auskommentiert.

Delphi-Quellcode:
class function TSHA1.toBase64(Res: TSHA1Res): String;
//const Base64: array[0 .. 63] of Char = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
const HexTable: array[0 .. 15] of Char = '0123456789ABCDEF';
var R: packed record Res: TSHA1Res; Fill: AnsiChar; end; A: packed array[0..20] of Byte absolute R; i: Integer;
begin
 R.Res := Res; R.Fill := '='; SetLength(Result, 28);
    for i := 0 to 6 do begin
// Result[i * 4 + 1] := Base64[ (A[i * 3 + 0] shr 2) and 63];
// Result[i * 4 + 2] := Base64[((A[i * 3 + 0] shl 4) or (A[i * 3 + 1] shr 4)) and 63];
// Result[i * 4 + 3] := Base64[((A[i * 3 + 1] shl 2) or (A[i * 3 + 2] shr 6)) and 63];
// Result[i * 4 + 4] := Base64[ A[i * 3 + 2] and 63];

      Result[i * 4 + 1] := HexTable[ (A[i * 3 + 0] shr 2) and 15];
      Result[i * 4 + 2] := HexTable[((A[i * 3 + 0] shl 4) or (A[i * 3 + 1] shr 4)) and 15];
      Result[i * 4 + 3] := HexTable[((A[i * 3 + 1] shl 2) or (A[i * 3 + 2] shr 6)) and 15];
      Result[i * 4 + 4] := HexTable[ A[i * 3 + 2] and 15];

 end;
end;
Wo liegt mein Fehler? Danke schon mal für die Hilfe ...
Ciao ... SittingDuck
iPhone Backup und mehr: iTwin v3.9 Beta ... Alternative Startleiste: Launcher v3.8 !
  Mit Zitat antworten Zitat