unit
Main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TFrm =
class
(TForm)
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
Edit3: TEdit;
Edit4: TEdit;
Edit5: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Button2: TButton;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
Label9: TLabel;
Button3: TButton;
Button4: TButton;
procedure
FormClose(Sender: TObject;
var
Action: TCloseAction);
procedure
Edit3KeyPress(Sender: TObject;
var
Key:
Char
);
procedure
FormShow(Sender: TObject);
procedure
Edit4KeyPress(Sender: TObject;
var
Key:
Char
);
procedure
Edit5KeyPress(Sender: TObject;
var
Key:
Char
);
procedure
Edit1KeyPress(Sender: TObject;
var
Key:
Char
);
procedure
Massiv();
procedure
Button3Click(Sender: TObject);
procedure
Button1Click(Sender: TObject);
procedure
Button4Click(Sender: TObject);
procedure
Button2Click(Sender: TObject);
private
public
end
;
const
n=
32
;
var
Frm: TFrm;
k1,k2,b:
integer
;
mas1:
array
[
1..
n]
of
char
= (
'а'
,
'б'
,
'в'
,
'г'
,
'д'
,
'е'
,
'ж'
,
'з'
,
'и'
,
'к'
,
'л'
,
'м'
,
'н'
,
'о'
,
'п'
,
'р'
,
'с'
,
'т'
,
'у'
,
'ф'
,
'х'
,
'ц'
,
'ч'
,
'ш'
,
'щ'
,
'ъ'
,
'ы'
,
'ь'
,
'э'
,
'ю'
,
'я'
,
'_'
);
mas3:
array
[
1..
n]
of
char
= (
'ц'
,
'у'
,
'к'
,
'е'
,
'н'
,
'г'
,
'ш'
,
'щ'
,
'з'
,
'х'
,
'ъ'
,
'ф'
,
'ы'
,
'в'
,
'а'
,
'п'
,
'р'
,
'о'
,
'л'
,
'д'
,
'ж'
,
'э'
,
'я'
,
'ч'
,
'с'
,
'_'
,
'м'
,
'и'
,
'т'
,
'ь'
,
'б'
,
'ю'
);
mas2:
array
[
1..
n]
of
char
;
implementation
{$R *.dfm}
procedure
TFrm
.
FormClose(Sender: TObject;
var
Action: TCloseAction);
begin
Application
.
Terminate;
end
;
procedure
Control(
var
ch:
char
;
var
l:TEdit);
begin
case
ch
of
'0'
..
'9'
:;
#
8
:;
else
ch:=#
0
;
end
;
end
;
procedure
TFrm
.
Massiv();
var
i,j,r:
integer
;
label
gt;
begin
j:=
1
;
i:=j;
Randomize;
while
i<=n
do
begin
label7
.
Caption:=label7
.
Caption + mas1[i];
inc(i);
end
;
while
j<=n+
1
do
begin
gt:
i:=random(n)+
1
;
for
r:=
1
to
j-
1
do
if
mas2[r]<>mas1[i]
then
mas2[j]:=mas1[i]
else
goto
gt;
label9
.
Caption:=label9
.
Caption + mas2[j];
inc(j);
end
;
end
;
procedure
TFrm
.
Edit3KeyPress(Sender: TObject;
var
Key:
Char
);
begin
if
key=#
13
then
Edit4
.
SetFocus;
Control(key, Edit3);
end
;
procedure
TFrm
.
FormShow(Sender: TObject);
begin
Edit3
.
SetFocus;
Massiv;
end
;
procedure
TFrm
.
Edit4KeyPress(Sender: TObject;
var
Key:
Char
);
begin
if
key=#
13
then
Edit5
.
SetFocus;
Control(key, Edit4);
end
;
procedure
TFrm
.
Edit5KeyPress(Sender: TObject;
var
Key:
Char
);
begin
if
key=#
13
then
Edit1
.
SetFocus;
Control(key, Edit5);
end
;
procedure
TFrm
.
Edit1KeyPress(Sender: TObject;
var
Key:
Char
);
begin
case
key
of
'а'
..
'я'
:;
'ё'
:;
'_'
:;
#
8
:;
else
key:=#
0
;
end
;
if
key=#
13
then
Edit2
.
SetFocus;
end
;
procedure
TFrm
.
Button3Click(Sender: TObject);
begin
Label7
.
Caption:=
''
;
Label9
.
Caption:=
''
;
Massiv;
end
;
procedure
TFrm
.
Button1Click(Sender: TObject);
label
l;
var
f,i,j,d,z:
integer
;
begin
Edit2
.
Text:=
''
;
try
if
(edit1
.
Text=
''
)
or
(edit3
.
Text=
''
)
or
(edit4
.
Text=
''
)
or
(edit5
.
Text=
''
)
then
begin
ShowMessage(
'Заполните все поля'
);
exit;
end
;
f:=
0
;
if
(StrToInt(Edit3
.
Text)
mod
2
=
0
)
and
(StrToInt(Edit4
.
Text)
mod
2
=
0
)
then
begin
ShowMessage(
'Коэффициенты должны быть нечётными!'
);
Edit3
.
Text:=
''
;
Edit4
.
Text:=
''
;
Edit3
.
SetFocus;
f:=
1
;
end
;
if
(StrToInt(Edit3
.
Text)
mod
2
=
0
)
then
begin
ShowMessage(
'Коэффициенты должны быть нечётными!'
);
f:=
2
;
Edit3
.
SetFocus;
Edit3
.
Text:=
''
;
end
;
if
(StrToInt(Edit4
.
Text)
mod
2
=
0
)
then
begin
ShowMessage(
'Коэффициенты должны быть нечётными!'
);
f:=
3
;
Edit4
.
SetFocus;
Edit4
.
Text:=
''
;
end
;
if
Edit5
.
Text =
''
then
begin
ShowMessage(
'Введите b!'
);
Edit5
.
SetFocus;
end
;
k1:=StrToInt(Edit3
.
Text);
k2:=StrToInt(Edit4
.
Text);
b:=StrToInt(Edit5
.
Text);
z:=
1
;
for
d:=
1
to
Length(Edit1
.
Text)
do
begin
for
i:=
1
to
n
do
if
Edit1
.
Text[d] = mas1[i]
then
begin
j:=(k1*i+k2)
mod
n;
if
j=
0
then
j:=n;
Edit2
.
Text:=Edit2
.
Text + mas2[j];
if
d
mod
b =
0
then
Edit2
.
Text:=Edit2
.
Text +
'_'
;
end
;
for
z:=
1
to
n
do
if
Edit2
.
Text=Edit2
.
Text + mas2[j]
then
begin
j:=(k1*z*k2)
mod
n;
if
j=
0
then
j:=n;
Edit2
.
Text:=Edit2
.
Text + mas3[j];
end
;
end
;
except
on
EConvertError
do
begin
if
(f=
1
)
or
(f=
2
)
or
(f=
3
)
then
exit;
MessageDlg(
'Там пусто!'
, mtWarning,[mbok],
0
);
if
Edit3
.
Text=
''
then
Edit3
.
SetFocus;
if
Edit4
.
Text=
''
then
Edit4
.
SetFocus;
if
(Edit3
.
Text=
''
)
and
(Edit4
.
Text=
''
)
then
Edit3
.
SetFocus;
end
;
end
;
Edit1
.
Text:=
''
;
end
;
procedure
TFrm
.
Button4Click(Sender: TObject);
begin
Edit1
.
Text:=
''
;
Edit2
.
Text:=
''
;
end
;
procedure
TFrm
.
Button2Click(Sender: TObject);
var
d,t,g,e,o:
integer
;
st:
string
;
begin
if
(edit2
.
Text=
''
)
or
(edit3
.
Text=
''
)
or
(edit4
.
Text=
''
)
or
(edit5
.
Text=
''
)
then
begin
ShowMessage(
'Заполните все поля'
);
exit;
end
;
t:=
0
;
st:=Edit2
.
Text;
for
g:=
1
to
length(st)
do
if
t=b
then
begin
t:=
1
;
delete (st, g ,
1
);
end
else
t:=t+
1
;
for
d:=
1
to
length(st)
do
begin
for
o:=
1
to
n
do
begin
e:=(k1*o+k2)
mod
n;
if
e=
0
then
e:=n;
if
st[d]=mas2[e]
then
Edit1
.
Text:=Edit1
.
Text+mas1[o];
end
;
end
;
end
;
end
.