Stolar228

(N-IDE) ASCII+ lite

Jan 14th, 2019
368
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 3.97 KB | None | 0 0
  1. uses crt;
  2. function perev(x:string):integer;
  3. var
  4. g:integer;
  5. begin
  6.   val(x, perev, g);
  7. end;
  8. ////////////модифицированное ASCII кодирование//////////////
  9. function code_simv(kod:integer;slovo,simv:string):string;
  10. var
  11. i,j,g:integer;
  12. slovofinal,a:string;
  13. begin
  14.         for g := 1 to kod do begin
  15.         slovofinal:='';
  16.           for i := 1 to length(slovo) do
  17.             begin
  18.               j:=0;
  19.               while true do
  20.                 begin
  21.                   j := j + 1;
  22.                   if copy(slovo, i, 1) = chr(j) then
  23.                     begin
  24.                       slovofinal:=slovofinal + j+simv;
  25.                       break;
  26.                     end;
  27.                 end;
  28.              end;
  29.              slovo:=slovofinal;
  30.             end;
  31.            code_simv:=slovofinal;
  32. end;
  33.  
  34. function decode_simv(kod:integer;slovo,simv:string):string;
  35. var
  36.   i,g,j:integer;
  37.   slovofinal,buf:string;
  38. begin
  39.         for g := 1 to kod do begin
  40.         slovofinal:='';
  41.           for i := 1 to length(slovo) do
  42.             begin
  43.               if copy(slovo, i, 1 ) <> simv then
  44.                 buf := buf + copy(slovo, i, 1)
  45.                else
  46.               while true do
  47.                 begin
  48.                   j:=j+1;
  49.                   if buf = j+'' then begin
  50.                       slovofinal:= slovofinal + chr(j);
  51.                       buf:='';
  52.                       j:=0;
  53.                       break;
  54.                     end;
  55.                 end;
  56.                
  57.                 end;
  58.                 slovo:=slovofinal;
  59.                 decode_simv:=slovofinal;
  60.             end;
  61. end;
  62. /////////////////
  63. var
  64. key, simv,a, simvf, slovo,name, slovofinal:String;
  65. j:integer;
  66. textt:textfile ;
  67. begin
  68.   simv:='/';
  69.   name:='save';
  70.   clrscr;
  71.   while true do
  72.     begin
  73.       write(simv, '>');
  74.       readln(key);
  75.       if key = 'code' then
  76.         begin
  77.           write('  шифрований:');
  78.           readln(j);
  79.           if j < 1 then
  80.             begin
  81.               j := 1;
  82.               writeln('    ERROR (',j,')');
  83.             end else
  84.           if j > 4 then
  85.             begin
  86.               j := 4;
  87.               writeln('    ERROR(',j,')');
  88.             end;
  89.           write('  было: ');
  90.           readln(slovo);
  91.           slovofinal:=code_simv(j, slovo, simv);
  92.           writeln('  стало: ', slovofinal);
  93.           assign(textt, name+'.saf');
  94.           rewrite(textt);
  95.           writeln(textt,j);
  96.           writeln(textt,slovofinal);
  97.           writeln(textt,simv);
  98.           close(textt);
  99.         end else
  100.       if key = 'decode' then
  101.         begin
  102.           write('  шифрований:');
  103.           readln(j);
  104.           if j < 1 then
  105.             begin
  106.               j := 1;
  107.               writeln('    ERROR (',j,')');
  108.             end else
  109.           if j > 4 then
  110.             begin
  111.               j := 4;
  112.               writeln('    ERROR(',j,')');
  113.             end;
  114.           write('  было: ');
  115.           readln(slovo);
  116.           slovofinal:=decode_simv(j, slovo, simv);
  117.           writeln('  стало: ', slovofinal);
  118.         end else
  119.       if key = 'decodefile' then
  120.         begin
  121.           assign(textt, name+'.saf');
  122.           reset(textt);
  123.           readln(textt,a);
  124.           readln(textt, slovo);
  125.           readln(textt, simvf);
  126.           close(textt);
  127.           j := perev(a);
  128.           writeln('  шифрований: ', a);
  129.           writeln('  было: ', slovo);
  130.           writeln('  стало: ', decode_simv(j, slovo, simvf));
  131.         end else
  132.       if key = 'open' then
  133.         begin
  134.           write('имя файла(без расширения): ');
  135.           readln(name);
  136.          
  137.         end else
  138.       if key = 'simv' then
  139.         begin
  140.           write('  символ: ');
  141.           readln(simv);
  142.         end else
  143.       if key = 'clear' then
  144.         clrscr else
  145.       if key = 'exit' then
  146.         break else
  147.           writeln('  ERROR');
  148.     end;
  149. end.
Advertisement
Add Comment
Please, Sign In to add comment