21.10.2016, 10:04
|
Прохожий
|
|
Регистрация: 02.10.2016
Сообщения: 18
Версия Delphi: Delphi 7
Репутация: 10
|
|
Я сделала так как вы сказали, но у меня все равно программа не правильно расшифровывает(шифрует?)
вот сам код
Код:
var
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;
begin
write('введите кол-во строк в матрице : ');
readln(r);
write('введите кол-во столбцов в матрице : ');
readln(b);
//----
SetLength(Textmatr,r);
For I := Low(Textmatr) To High(Textmatr) Do SetLength(Textmatr[i],b);
SetLength(key1,r);
SetLength(key2,b);
repeat
Write('введите текст для кодировки: ');
Readln(Text);
kolsimvolov:=Length(text);
m:=True;
if kolsimvolov>r*b then
m:=False;
if not(m) then
writeln('Кол-во символов не должно привышать r*b ');
until m;
If (kolsimvolov div (r*b))<> 1 then
begin
text:=text+' ';
Inc(kolsimvolov);
end;
Repeat
Writeln('Введите ключ 1 , состоящий из ',r,' символов, через "Enter"');
for i:=0 to r-1 do
Readln(key1[i]);
p:=true;
for i := 0 to r - 2 do
for j := i + 1 to r - 1 do
if (key1[i]=key1[i+1]) 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 := 1 to b - 2 do
for j := i + 1 to b - 1 do
if (key2[i]=key2[i+1]) then
t:=false;
If Not(t) then
writeln('Все символы должны быть различны!');
Until t;
Writeln;
//----------------------------------------------------—
Writeln;
//----------------------------------------------------—
For i:=0 to r-1 do
For j:=0 to b-1 do
BEGIN
//OutPutDebugString(PWideChar(inttostr(i)+' '+inttostr(j)));
Textmatr[key1[i]-1,j]:=Text[(i)*b+j+1];
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;
//----------------------------------------------------—
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);
//-----------------------------------------------------—
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-1)*r+key1[i],1);
Text_3:=Text_3+S;
end;
Writeln('Раскодированный текст:',' ',Text_3);
//-----------------------------------------------------—
Writeln;
Readln;
End.
а должно быть вот так гг.png
|