Einzelnen Beitrag anzeigen

MaOfDe

Registriert seit: 3. Jan 2004
Ort: Berlin
73 Beiträge
 
Delphi 6 Personal
 
#3

Re: >Multiplikative Inversion bei IDEA<

  Alt 4. Apr 2004, 11:20
OK, hab was gefunden... haut zwar nicht hin mit X * MulInv(X)=1, aber immerhin ein Anfang.

Delphi-Quellcode:
//written by Dave Barton (davebarton@bigfoot.com)
function MulInv(x: word): word;
var
  t0, t1, q, y: word;
begin
  if x<= 1 then
  begin
    Result:= x;
    Exit;
  end;
  t1:= DWord($10001) div x;
  y:= DWord($10001) mod x;
  if y= 1 then
  begin
    Result:= (1 - t1) and $FFFF;
    Exit;
  end;
  t0:= 1;
  repeat
    q:= x div y;
    x:= x mod y;
    t0:= t0 + (q*t1);
    if x= 1 then
    begin
      Result:= t0;
      Exit;
    end;
    q:= y div x;
    y:= y mod x;
    t1:= t1 + (q*t0);
  until y= 1;
  Result:= (1-t1) and $FFFF;
end;
  Mit Zitat antworten Zitat