Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- uses crt;
- function perev(x:string):integer;
- var
- g:integer;
- begin
- val(x, perev, g);
- end;
- ////////////модифицированное ASCII кодирование//////////////
- function code_simv(kod:integer;slovo,simv:string):string;
- var
- i,j,g:integer;
- slovofinal,a:string;
- begin
- for g := 1 to kod do begin
- slovofinal:='';
- for i := 1 to length(slovo) do
- begin
- j:=0;
- while true do
- begin
- j := j + 1;
- if copy(slovo, i, 1) = chr(j) then
- begin
- slovofinal:=slovofinal + j+simv;
- break;
- end;
- end;
- end;
- slovo:=slovofinal;
- end;
- code_simv:=slovofinal;
- end;
- function decode_simv(kod:integer;slovo,simv:string):string;
- var
- i,g,j:integer;
- slovofinal,buf:string;
- begin
- for g := 1 to kod do begin
- slovofinal:='';
- for i := 1 to length(slovo) do
- begin
- if copy(slovo, i, 1 ) <> simv then
- buf := buf + copy(slovo, i, 1)
- else
- while true do
- begin
- j:=j+1;
- if buf = j+'' then begin
- slovofinal:= slovofinal + chr(j);
- buf:='';
- j:=0;
- break;
- end;
- end;
- end;
- slovo:=slovofinal;
- decode_simv:=slovofinal;
- end;
- end;
- /////////////////
- var
- key, simv,a, simvf, slovo,name, slovofinal:String;
- j:integer;
- textt:textfile ;
- begin
- simv:='/';
- name:='save';
- clrscr;
- while true do
- begin
- write(simv, '>');
- readln(key);
- if key = 'code' then
- begin
- write(' шифрований:');
- readln(j);
- if j < 1 then
- begin
- j := 1;
- writeln(' ERROR (',j,')');
- end else
- if j > 4 then
- begin
- j := 4;
- writeln(' ERROR(',j,')');
- end;
- write(' было: ');
- readln(slovo);
- slovofinal:=code_simv(j, slovo, simv);
- writeln(' стало: ', slovofinal);
- assign(textt, name+'.saf');
- rewrite(textt);
- writeln(textt,j);
- writeln(textt,slovofinal);
- writeln(textt,simv);
- close(textt);
- end else
- if key = 'decode' then
- begin
- write(' шифрований:');
- readln(j);
- if j < 1 then
- begin
- j := 1;
- writeln(' ERROR (',j,')');
- end else
- if j > 4 then
- begin
- j := 4;
- writeln(' ERROR(',j,')');
- end;
- write(' было: ');
- readln(slovo);
- slovofinal:=decode_simv(j, slovo, simv);
- writeln(' стало: ', slovofinal);
- end else
- if key = 'decodefile' then
- begin
- assign(textt, name+'.saf');
- reset(textt);
- readln(textt,a);
- readln(textt, slovo);
- readln(textt, simvf);
- close(textt);
- j := perev(a);
- writeln(' шифрований: ', a);
- writeln(' было: ', slovo);
- writeln(' стало: ', decode_simv(j, slovo, simvf));
- end else
- if key = 'open' then
- begin
- write('имя файла(без расширения): ');
- readln(name);
- end else
- if key = 'simv' then
- begin
- write(' символ: ');
- readln(simv);
- end else
- if key = 'clear' then
- clrscr else
- if key = 'exit' then
- break else
- writeln(' ERROR');
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment