Вот программа:
program Project15;
{$APPTYPE CONSOLE}
uses
Windows,
SysUtils;
var
q, h: array of integer;
Text, Text_1, Text_2, text_3, S: String;
i, j, kolsimvolov: integer;
key1: array of Byte;
key2: array of Byte;
p, m,t: Boolean;
r, b: integer;
Textmatr: Array of array of Char;
c:char;
begin
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
repeat
writeln('Выберите действие');
writeln('1-зашифровать текст');
writeln('2-расшифровать текст');
writeln('другое - выход');
readln(c);
write('введите кол-во строк в матрице : ');
readln(r);
write('введите кол-во столбцов в матрице : ');
readln(b);
//--—
setlength(q, r);
setlength(h, b);
setlength(key1, r);
setlength(key2, b);
setlength(Textmatr, r, b);
repeat
Write('введите текст для кодировки: ');
Readln(Text);
kolsimvolov:=Length(text);
m := (kolsimvolov <= r * b);
if not(m) then
writeln('Кол-во символов не должно привышать r*b ');
until m;
Repeat
Writeln('Введите ключ 1 , состоящий из ',r,' символов, через "Enter"');
for i:=0 to r-1 do
Readln(key1[i]);
p:=true;
for i:=0 to r-1 do
for j:=i+1 to r-1 do
if (key1[i] = key1[j]) then
p := False;
If Not(p) then
writeln('Все символы должны быть различны!');
Until p;
Repeat
Writeln('Введите ключ 2, состоящий из ',b,' символов, через "Enter"');
for i:=0 to b-1 do
Readln(key2[i]);
t:=true;
for i:=0 to b-1 do
for j:=i+1 to b-1 do
if (key2[i]=key2[j]) then
t:=false;
If Not(t) then
writeln('Все символы должны быть различны!');
Until t;
Writeln;
//----------------------------------------------------—
for i := 0 to r - 1 do
for j := 0 to b - 1 do
begin
//OutPutDebugString(PWideChar(inttostr(i)+' '+inttostr(j)));
if i * b + j + 1 <= Length(Text) then
Textmatr[key1[i] - 1, j] := Text[(i) * b + j + 1]
else
Textmatr[key1[i] - 1, j] := ' ';
end;
Writeln(' k1\k2 ');
For i:=0 to r-1 do
begin
Write(' ',i,' ');
For j:=0 to b-1 do
write(' ',textmatr[i,j],' ');
Writeln;
end;
case c of
'1':
begin
//----------------------------------------------------—
Text_1:='';
For j:=0 to b-1 do
for i:=0 to r-1 do
begin
S:=textmatr[i,key2[j]-1];
Text_1:=Text_1+S;
end;
Writeln('Закодированный текст:',' ',text_1);
end;
//-----------------------------------------------------—
'2':
begin
Text_2:='';
For j:=0 to b-1 do
begin
S:=Copy(Text_1,(key2[j]-1)*r+1,r);
Text_2:=Text_2+S;
end;
Text_3:='';
For i:=0 to r-1 do
For j:=0 to b-1 do
begin
S:=Copy(Text_2,(j)*r+key1[i],1);
Text_3:=Text_3+S;
end;
Writeln('Раскодированный текст:',' ',Text_3);
//-----------------------------------------------------—
write('Нажмите Enter');
Readln;
End;
else
begin
writeln('Программа завершена');
//exit;
end;
end;
until not (c in ['1', '2']);
end.