pisze program który koduje tekst z pliku txt do pliku dat i potem rozkodowuje tekst z pliku dat do pliku txt:
var
key : String;
procedure Code;
var
pfileIn, pfileOut : Text;
Result, C : Char;
passingCounter : Integer;
begin
Assign(pfileIn, 'TEKST.TXT');
Reset(pfileIn);
Assign(pfileOut, 'KOD.DAT');
Rewrite(pfileOut);
passingCounter:=0;
while not eof(pfileIn) do
begin
Read(pfileIn, c);
Result:=Chr(Ord(Key[passingCounter]) xor Ord(c));
Write(pfileOut, Result);
inc(passingCounter);
if passingCounter > length(key) then
passingCounter:=0;
end;
Close(pfileIn);
Close(pfileOut);
end;
// i procka rozkodowująca
procedure Decode;
var
pfileIn, pfileOut : Text;
Result, C : Char;
passingCounter : Integer;
begin
Assign(pfileIn, 'KOD.DAT');
Reset(pfileIn);
Assign(pfileOut, 'WYNIK.TXT');
Rewrite(pfileOut);
passingCounter:=0;
while not eof(pfileIn) do
begin
Read(pfileIn, c);
Result:=Chr(Ord(Key[passingCounter]) xor Ord(c));
Write(pfileOut, Result);
inc(passingCounter);
if passingCounter > length(key) then
passingCounter:=0;
end;
Close(pfileIn);
Close(pfileOut);
end;
Klucz jest standardowo wczytywany z klawiatury. Problem tkwi w tym, że
po rozkodowaniu nie otrzymuje całego tekstu wejściowego tylko jego fragment.
Siedze już troche i nie moge wykminić czemu sie tak dzieje.
Może ktoś mógłby rzucić okiem?