unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
mmo1: TMemo;
mmo2: TMemo;
btn1: TButton;
btn2: TButton;
lbl1: TLabel;
lbl2: TLabel;
edt1: TEdit;
lbl3: TLabel;
rg1: TRadioGroup;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
const alfa:array[0..65] of char = ('а','б','в','г','д','е','ё','ж','з','и','й','к','л','м','н','о','п','р','с','т','у','ф','х','ц','ч','ш','щ','ъ','ы','ь','э','ю','я','А','Б','В','Г','Д','Е','Ё','Ж','З','И','Й','К','Л','М','Н','О','П','Р','С','Т','У','Ф','Х','Ц','Ч','Ш','Щ','Ъ','Ы','Ь','Э','Ю','Я');
var
Form1: TForm1;
a:array[0..65] of char;
i, j, k: integer;
s, s2, stroki, Last:string;
c:char;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
if rg1.ItemIndex=0
then begin
For i:=0 to 65 do
begin
a[i]:= alfa[(i+1) mod 66];
end;
// шифр
k := StrToInt(edt1.Text);
s := mmo1.Lines.Text;
for i := 1 to length(s) do
for j := 0 to 65 do
if s[i] = a[j] then s2 := s2+a[(66+(j+k)) mod 66];
mmo2.Lines.Text := s2;
s2 := '';
end;
if rg1.ItemIndex=1
then begin
i := 1;
if Length(mmo1.Text) mod 2 = 0
then begin
stroki := mmo1.Text;
Last := '';
end
else begin
stroki := Copy(mmo1.Text, 1, Length(mmo1.Text) - 1);
Last := Copy(mmo1.Text, Length(mmo1.Text), 1);
end;
while i <= Length(stroki) do
begin
c := stroki[i];
stroki[i] := stroki[i + 1];
stroki[i + 1] := c;
i := i + 2;
end;
mmo2.Text := stroki + Last;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
if rg1.ItemIndex=0
then begin
s2:='';
k := StrToInt(edt1.Text);
s := mmo1.Lines.Text;
for i := 1 to length(s) do
for j := 0 to 65 do
if s[i] = a[j] then s2 := s2+a[(66+(j-k)) mod 66];
mmo2.Lines.Text := s2;
s2 := '';
if rg1.ItemIndex=1
then begin
if rg1.ItemIndex=1
then begin
i := 1;
if Length(mmo2.Text) mod 2 = 0
then begin
stroki := mmo2.Text;
Last := '';
end
else begin
stroki := Copy(mmo2.Text, 1, Length(mmo1.Text) + 1);
Last := Copy(mmo2.Text, Length(mmo1.Text), 1);
end;
while i <= Length(stroki) do
begin
c := stroki[i];
stroki[i] := stroki[i - 1];
stroki[i - 1] := c;
i := i - 2;
end;
mmo1.Text := stroki + Last;
end;
end;
end;
end;
end.