unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, FGInt;

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Button1: TButton;
    Button2: TButton;
    SaveDialog1: TSaveDialog;
    SaveDialog2: TSaveDialog;
    Button3: TButton;
    OpenDialog1: TOpenDialog;
    OpenDialog2: TOpenDialog;
    SaveDialog3: TSaveDialog;
    Button4: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure QPGen(QLength:integer; Plength:integer; var QDec:string; var PDec:string);
	var
		QBin:string;
		PBin:string;
		QFullBaseBin:string;
		PFullBaseBin:string;
		QFGInt:TFGInt;
		PFGInt:TFGInt;
		QFullBase:TFGInt;
		PFullBase:TFGInt;
		QFull:TFGInt;
		PFull:TFGInt;
		PSub1:TFGInt;
		MFGInt:TFGint;
		QQFGInt:TFGInt;
		ok:boolean;
		i:integer;
	begin
		randomize;
		QBin:='1';
		while QLength > (length(QBin)) do
			begin
				QBin:=QBin+IntToStr(random(2));
			end;
		Base2StringToFGInt(QBin,QFGInt);
		FGIntPrimeTest(QFGInt,QLength,ok);
		FGIntToBase10String(QFGInt,QDec);
		QFullBaseBin:='1';
		for i:=1 to QLength do
			QFullBaseBin:=QFullBaseBin+'0';
		Base2StringToFGInt(QFullBaseBin,QFullBase);
		Base2StringToFGInt('1',QFull);
		while not(ok) do
			begin
				FGIntAddMod(QFGInt,QFull,QFullBase,QFGInt);
				FGIntPrimeTest(QFGInt,QLength,ok);
			end;
		FGIntToBase10String(QFGInt,QDec);
 		// q
		PBin:='1';
		for i:=2 to PLength do
			 PBin:=PBin+'0';
		Base2StringToFGInt(PBin,PFGInt);
		FGIntPrimetest(PFGInt,PLength,ok);
		FGIntToBase10String(PFGInt,PDec);
		PFullBaseBin:='1';
		for i:=1 to PLength do
			PFullBaseBin:=PFullBaseBin+'0';
		Base2StringToFGInt(PFullBaseBin,PFullBase);
		Base2StringToFGInt('1',PFull);
		FGIntSub(PFGInt,PFull,PSub1);
		FGIntDivMod(PSub1,QFGInt,QQFGInt,MFGInt);
		repeat
			FGIntMulMod(QFGInt,QQFGInt,PFullBase,PSub1);
			FGIntAddMod(PSub1,PFull,PFullBase,PFGInt);
			ok:=false;
			FGIntPrimeTest(PFGInt,PLength,ok);
			FGIntAddMod(QQFGInt,PFull,PFullBase,QQFGInt);
		until ok;
		FGIntToBase10String(PFGInt, PDec);
    // p
	end;
procedure GGen(QDec,PDec:string; var GDec:string);
	var
		One:TFGInt;
		PFGInt:TFGInt;
		QFGInt:TFGInt;
		PSub1:TFGInt;
		QQFGInt:TFGInt; // 