Einzelnen Beitrag anzeigen

qwertz543221
(Gast)

n/a Beiträge
 
#1

probedivision -abbruch von schleife funktioniert nicht

  Alt 8. Okt 2009, 18:00
ich möchte folgende proceudre (probedivision)abrrechen und mit dem restlichen code weitermachen, doch wieso kann ich die schleife nicht beenden, wenn die abbruchbedingung erreicht ist?
Delphi-Quellcode:
function tform1.miller_rabin(n: ansistring; t: longint):boolean;
label l;
var
  n1,n2, y, r, x: string;
  s,j,i: longint;
const
 primes:array[1..5]of string=('2','3','5','7');//in meinem fall deujtlich größer
   // probedivison
function probedivision(n:ansistring):boolean;
var
 I:longint;
begin
i:=1;
result:=true;
while i<=5{9549} do
begin
if mathe.modulo(n,primes[i])='0'
 then
 begin
 result:=false;
 break;
 end
   else i:=i+1;
end;
end;

begin
result := false;
if Mathe.istGerade(n)
  then exit;

begin
{get n1 = n - 1} 
{get n2 = n - 2}
if probedivision(n)=true
 then
  begin
  n1 := n;
  Mathe.Minus1(n1);
  n2 := n1;
  Mathe.Minus1(n2);

  {calculate r,s with n-1=2^s*r} 
  r := n1;
  s := 0;
  while Mathe.istGerade(r) do
   begin
   r := Mathe.Quotient(r,'2');
   inc(s);
   end;
   while t>0 do
   begin
    {generate a in the range 2<=a<n-1, calculate y = a^r mod n}
    y := Mathe.Zufallszahl('2', n2);
    y := Mathe.PotenzModulo(y,r,n);
    {if y<>1 and y<>n-1 do}
    if (y<>'1') and (y<>n1)
     then
     begin
     j := 1;
     while (j <= s-1) and (y<>n1) do
     begin
     y := Mathe.ProduktModulo(y,y,n);
     {if y=1 then composite} 
     if y='1
      then exit;
     inc(j);
     end;
      {if y<>n1 then composite} 
      if y<>n1 then exit;
    end;
    dec(t);
  end;
  {probably prime now}
  result := true;
end;
end;
end;
  Mit Zitat antworten Zitat