unit rMain; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Buttons, StdCtrls, FGInt, FGIntPrimeGeneration, FGIntRSA, ExtCtrls, ComCtrls, ImgList, ToolWin; type TForm1 = class(TForm) Memo1: TMemo; SpeedButton7: TSpeedButton; OpenDialog1: TOpenDialog; OpenDialog2: TOpenDialog; SaveDialog1: TSaveDialog; SaveDialog2: TSaveDialog; Panel1: TPanel; Panel3: TPanel; Memo2: TMemo; Label1: TLabel; Label2: TLabel; ToolBar1: TToolBar; ToolButton1: TToolButton; ImageList1616: TImageList; ToolButton2: TToolButton; SpeedButton1: TSpeedButton; SpeedButton2: TSpeedButton; ToolBar2: TToolBar; ToolButton3: TToolButton; ToolButton4: TToolButton; SpeedButton3: TSpeedButton; SpeedButton4: TSpeedButton; SpeedButton6: TSpeedButton; SpeedButton5: TSpeedButton; procedure SpeedButton3Click(Sender: TObject); procedure SpeedButton4Click(Sender: TObject); procedure SpeedButton5Click(Sender: TObject); procedure SpeedButton6Click(Sender: TObject); procedure SpeedButton7Click(Sender: TObject); procedure FormCreate(Sender: TObject); procedure SpeedButton1Click(Sender: TObject); procedure SpeedButton2Click(Sender: TObject); procedure ToolButton1Click(Sender: TObject); procedure ToolButton2Click(Sender: TObject); procedure ToolButton3Click(Sender: TObject); procedure ToolButton4Click(Sender: TObject); private { Private declarations } protected keypresent:boolean; public { Public declarations } end; var Form1: TForm1; // n, e, d, dp, dq, p, q, phi, one, two, gcd, temp, nilgint : TFGInt; // n - произведение p*q // phi-функция Эйлера phi=(q-1)*(p-1) // gcd - наибольший общий делитель чисел phi и e // e - открытый ключ // d - закрытый ключ implementation uses genkey; {$R *.dfm} procedure TForm1.SpeedButton3Click(Sender: TObject); var f:TextFile; s:string; begin {Открыть текст} if OpenDialog1.Execute and FileExists(OpenDialog1.FileName) then begin AssignFile(F,OpenDialog1.FileName); Reset(f); Memo1.Lines.Clear; while not EOF(f) do begin Readln(f,s); Memo1.Lines.Add(s); end; CloseFile(f); end; end; procedure TForm1.SpeedButton4Click(Sender: TObject); begin {Сохранение} if SaveDialog1.Execute then Memo1.Lines.SaveToFile(SaveDialog1.FileName); end; procedure TForm1.SpeedButton5Click(Sender: TObject); var f:TextFile; s:string; begin {Открыть шифр} if OpenDialog2.Execute and FileExists(OpenDialog2.FileName) then begin AssignFile(F,OpenDialog2.FileName); Reset(f); Memo2.Lines.Clear; while not EOF(f) do begin Readln(f,s); Memo2.Lines.Add(s); end; CloseFile(f); end; end; procedure TForm1.SpeedButton6Click(Sender: TObject); begin if SaveDialog2.Execute then Memo2.Lines.SaveToFile(SaveDialog2.FileName); end; procedure TForm1.SpeedButton7Click(Sender: TObject); begin {Вызов окна генерации ключа} KeyPresent:=true; Form2.Show; end; procedure TForm1.FormCreate(Sender: TObject); begin KeyPresent:=false; end; procedure TForm1.SpeedButton1Click(Sender: TObject); var source,dest:string; i:integer; begin {Выполнение кодирования} Memo2.Lines.Clear; if keypresent then for i:=0 to Memo1.Lines.Count-1 do begin source:=Memo1.lines.Strings[i]; RSAEncrypt(source, e, n, dest); Memo2.lines.Add(dest); end else begin ShowMessage('Необходимо сгенерировать ключ'); //Form2.Show; end; end; procedure TForm1.SpeedButton2Click(Sender: TObject); var source,dest:string; i:integer; begin {Выполнение раскодирования} Memo1.Lines.Clear; if keypresent then for i:=0 to Memo2.Lines.Count-1 do begin source:=Memo2.lines.Strings[i]; RSADecrypt(source, d, n, Nilgint, Nilgint, Nilgint, Nilgint, dest); Memo1.lines.Add(dest); end else ShowMessage('Необходимо ввести ключ'); end; procedure TForm1.ToolButton1Click(Sender: TObject); begin SpeedButton3.Click; end; procedure TForm1.ToolButton2Click(Sender: TObject); begin SpeedButton4.Click; end; procedure TForm1.ToolButton3Click(Sender: TObject); begin SpeedButton5.Click; end; procedure TForm1.ToolButton4Click(Sender: TObject); begin SpeedButton6.Click; end; end.