Advertisement
LOVEGUN

Bac 2017

Apr 9th, 2021
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.69 KB | None | 0 0
  1. Program bac2017;
  2. Uses Wincrt;
  3. Type
  4.   tab = Array [1..10,1..10] Of Char;
  5. Var
  6.   f1,f2: Text;
  7.   cle: String;
  8.  
  9. Procedure creation (Var f1,f2:Text);
  10. Begin
  11.   Assign (f1,'c:\bac\source.txt');
  12.   Assign (f2,'c:\bac\result.txt');
  13. End;
  14.  
  15. Function verif (ch:String): Boolean;
  16. Var
  17.   i: Integer;
  18.   test: Boolean;
  19. Begin
  20.   i := 0;
  21.   Repeat
  22.     i := i+1;
  23.     test := (ch[i] In ['A'..'Z']) And (Pos(ch[i],ch)=i);
  24.   Until (i=Length(ch)) Or (test=False);
  25.   verif := test;
  26. End;
  27.  
  28. Procedure saisie (Var cle :String);
  29. Begin
  30.   Repeat
  31.     Write ('Saisir la clé: ');
  32.     Readln (cle);
  33.   Until (verif (cle)) And (Length(cle) In [5..10]);
  34. End;
  35. Function cryptage (ch,cle:String): String;
  36. Var
  37.   i,j,x: Integer;
  38.   t: tab;
  39. Begin
  40.   x := 0;
  41.   For i:=1 To (Length(ch) Div Length(cle)) Do
  42.     For j:=1 To Length(cle) Do
  43.       Begin
  44.         x := x+1;
  45.         t[i,j] := ch[x];
  46.       End;
  47.     x:=Length(ch);
  48.     ch:='';
  49.     For j:=1 To Length(cle) Do
  50.         Begin
  51.             ch:=ch+cle[j];
  52.             For i:=1 To (x Div Length(cle)) Do
  53.                     ch:=ch+t[i,j];
  54.         end;
  55.     cryptage:=ch;
  56. End;
  57. Procedure traitement (Var f1,f2:Text;cle:String);
  58. Var
  59.   i,n: Integer;
  60.   ch: String;
  61. Begin
  62.   Reset (f1);
  63.   Rewrite (f2);
  64.   While Not (Eof(f1)) Do
  65.     Begin
  66.       n := Length(cle)-(Length(ch) Mod Length(cle));
  67.       Readln (f1,ch);
  68.       If n<>0 Then
  69.         For i:=1 To n Do
  70.           ch := ch+' ';
  71.       Writeln (f2,cryptage(ch,cle));
  72.     End;
  73.   Close (f1);
  74.   Close (f2);
  75. End;
  76. procedure affiche (var f2:text);
  77. Var
  78. ch:string;
  79. Begin
  80.     reset (f2);
  81.     while not (eof(f2)) Do
  82.     Begin
  83.         readln (f2,ch);
  84.         writeln (ch);
  85.     end;
  86.     close (f2);
  87. end;
  88. Begin
  89.   creation (f1,f2);
  90.   saisie (cle);
  91.   traitement (f1,f2,cle);
  92.     affiche (f2);
  93. End.
  94.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement