Урок на Делфи 72. Шифр Виженера


задание на delphi. Как зашифровать-расшифровать текст с помощью шифра Виженера.

unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, ComCtrls, Spin, Grids, ValEdit;
type
TForm1 = class(TForm)
Label8: TLabel;
Label6: TLabel;
Memo5: TMemo;
Label11: TLabel;
Edit2: TEdit;
Label10: TLabel;
Memo6: TMemo;
Button2: TButton;
Label14: TLabel;
Memo4: TMemo;
Label13: TLabel;
Button4: TButton;
Memo1: TMemo;
procedure Button2Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
s: string;
implementation
uses Math;
{$R *.dfm}
procedure Code(var text: string; password: string);
var
i: integer;
begin
s:='';
for i := 1 to Length(text) do
begin
s:=s+password;
if Length(s)>=Length(text) then
break;
end;
Form1.Memo1.Lines.Add(s);
for i := 1 to Length(text) do
begin
text[i] := chr(ord(text[i]) + ord(s[i]));
end;
end;
procedure deCode(var text: string; password: string);
var
i: integer;
begin
s:='';
for i := 1 to Length(text) do
begin
s:=s+password;
if Length(s)>=Length(text) then
break;
end;
Form1.Memo1.Lines.Add(s);
for i := 1 to Length(text) do
text[i] := chr(ord(text[i]) - ord(s[i]));
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i:integer;
s:string;
begin
end;
procedure TForm1.Button2Click(Sender: TObject);
var q,w:integer;
b:string;
begin
Memo1.Clear;
Memo6.Clear;
b := Memo5.Text;
code(b, Edit2.Text);
Memo6.Text := b;
end;
procedure TForm1.Button4Click(Sender: TObject);
var q:string;
begin
Memo1.Clear;
q:=Memo6.Lines.Text;
decode(q, edit2.Text);
Memo4.Clear;
Memo4.Lines.Add(q);
end;
end.



Скачать