Einzelnen Beitrag anzeigen

gammatester

Registriert seit: 6. Dez 2005
999 Beiträge
 
#6

Re: MD5 HASH = 32 HEXZeichen convertto Dezimalzahl

  Alt 21. Jan 2010, 13:08
Zitat von boller78:
Wie komme ich vom HASH-Wert: 15819a364dbe86b956083bbd19992857f
auf die Dezimalzahl: 28586721999694642100505878794595370367
Als erstes mußt Du aus "999" im Hexwert "99" machen, sonst kommt nix vernünfiges raus. Ansonsten ist's halt eine normale Division eines Base256-Vektors (sprich array of byte) durch 10. Hier Dein korrigiertes Beispiel:
Delphi-Quellcode:
program t_b10;

{$ifdef WIN32}
  {$apptype console}
{$endif}


{---------------------------------------------------------------------------}
function base256_to_baseB(var a: array of byte; B: byte): string;
  {-bigendian base 256 number to base B string, a is destroyed}
const
  cmap: array[0..61] of char = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
var
  i,k: integer;
  w: word;
  d: byte;
  s: string;
begin
  s := '';
  {k is index of MSB of a}
  k := low(a);
  repeat
    {One repeat iteration calculates a := a div B;  d := a mod B}
    {initialize "carry"}
    w := 0;
    for i:=k to high(a) do begin
      {loop invariant: 0 <= w < B}
      w := (w shl 8) or a[i];
      if w>=B then begin
        d := w div B;
        w := w mod B;
      end
      else d:=0;
      a[i] := d;
    end;
    {set d to remainder, w is still < B!}
    d := byte(w);
    {add base R digit to result if d is not out of range}
    if d<sizeof(cmap) then s := cmap[d]+s
    else s := '?'+s;
    {if MSB(a) is zero increment lower bound}
    if a[k]=0 then inc(k);
  until k>high(a);
  base256_to_baseB := s;
end;

const
  HashBin : array[0..15] of byte = ($15,$81,$9a,$36,$4d,$be,$86,$b9,$56,$08,$3b,$bd,$19,$92,$85,$7f);
var
  s: string;
  tmp: array[0..15] of byte;
  i: integer;
begin
  {Copy Hash into tmp byte buffer}
  for i:=0 to 15 do tmp[i] := HashBin[i];
  s := base256_to_baseB(tmp, 10);
  writeln('Hash as decimal number: ', s);
end.
Ausgabe:
Code:
Borland Pascal Version 7.0  Copyright (c) 1983,92 Borland International
Hash as decimal number: 28586721999694642100505878794595370367
  Mit Zitat antworten Zitat