AGB  ·  Datenschutz  ·  Impressum  







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

from C# to delphi

Ein Thema von sdean · begonnen am 22. Dez 2022 · letzter Beitrag vom 30. Jan 2023
 
Benutzerbild von DeddyH
DeddyH

Registriert seit: 17. Sep 2006
Ort: Barchfeld
27.655 Beiträge
 
Delphi 12 Athens
 
#2

AW: from C# to delphi

  Alt 22. Dez 2022, 16:04
Completely untested (written in Notepad++):
Delphi-Quellcode:
function PQFactorize(pq: LongWord): LongWord;

  function gcd(left, right: LongWord): LongWord;
  var
    num: LongWord;
  begin
    while right <> 0 do
      begin
        num := left mod right;
        left := right;
        right := num;
      end;
    Result := left;
  end;

var
  g, q, x, y, z, res, a, other: LongWord;
  i, j, iter, lim: integer;
begin
  if pq < 2 then
    Exit(1);
  g := 0;
  i := 0;
  iter := 0;
  repeat
    q := LongWord(Random(16) + 17) mod (pq - 1);
    x := (LongWord(Random(MAXINT)) + LongWord(Random(MAXINT)) shl 31) mod (pq - 1) + 1;
    y := x;
    lim := 1 shl (math.Min(5, i) + 18);
    for j := 1 to lim - 1 do
      begin
        inc(iter);
        res := q;
        a := x;
        while x <> 0 do
          begin
            if (x and 1) <> 0 then
              res := (res + a) mod pq;
            a := (a + a) mod pq;
            x := x shr 1;
          end;
        x := res;
        if x < y then
          z := pq + x - y
        else
          z := x - y;
        g := gcd(z, pq);
        if g <> 1 then
          break;
        if (j and (j - 1)) = 0 then
          y := x;
      end;
    if (g > 1) and (g < pq) then
      break;
    inc(i);
  until (i >= 3) or (iter >= 1000);
  if (g <> 0) then
    begin
      other := pq div g;
      if (other < g) then
        g := other;
    end;
  Result := g;
end;
The keyword "static" implies that this is a static class function, so you have to declare it as such.
Detlef
"Ich habe Angst vor dem Tag, an dem die Technologie unsere menschlichen Interaktionen übertrumpft. Die Welt wird eine Generation von Idioten bekommen." (Albert Einstein)
Dieser Tag ist längst gekommen
  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 02:51 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 by Thomas Breitkreuz