Advertisement
LOVEGUN

Bac 2014 14h

Apr 23rd, 2021
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.95 KB | None | 0 0
  1. Program bac2014;
  2. Uses Wincrt;
  3. Type
  4.   mat = Array[1..5,1..5] Of Char;
  5. Var
  6.   msg,cle: String;
  7.   m: mat;
  8. Function verif1 (ch:String): Boolean;
  9. Var
  10.   i: Integer;
  11.   test: Boolean;
  12. Begin
  13.   i := 0;
  14.   Repeat
  15.     i := i+1;
  16.     test := ch[i] In ['A'..'Z',' '];
  17.   Until (test=False) Or (i=Length(ch));
  18.   verif1 := test;
  19. End;
  20.  
  21. Function verif2 (ch:String): Boolean;
  22. Var
  23.   i: Integer;
  24.   test: Boolean;
  25. Begin
  26.   i := 0;
  27.   Repeat
  28.     i := i+1;
  29.     test := (ch[i] In ['A'..'Z']) And (Pos(ch[i],ch)=i);
  30.   Until (i=Length(ch)) Or (test=False);
  31.   verif2 := (test) And (Pos('W',ch)=0);
  32. End;
  33.  
  34. Procedure saisie (Var msg,cle:String);
  35. Begin
  36.   Repeat
  37.     Write ('Saisir le message: ');
  38.     Readln (msg);
  39.   Until verif1 (msg);
  40.   Repeat
  41.     Write ('Saisir la cle: ');
  42.     Readln (cle);
  43.   Until verif2(cle);
  44. End;
  45.  
  46. Function recherche (c:Char;m:mat): String;
  47. Var
  48.   i,j: Integer;
  49.   x: String;
  50.   ch1: String;
  51. Begin
  52.   For i:=1 To 5 Do
  53.     For j:=1 To 5 Do
  54.       If (m[i,j]=c) Then
  55.         Begin
  56.           Str (i,x);
  57.           ch1 := x;
  58.           Str (j,x);
  59.           ch1 := ch1+x;
  60.         End;
  61.   recherche := ch1;
  62. End;
  63.  
  64. Procedure traitement (Var m:mat;msg,cle:String);
  65. Var
  66.   i,j,longc,x: Integer;
  67.   ch1: String;
  68.         f:text;
  69. Begin
  70.   longc := 0;
  71.   x := 0;
  72.   For i:=1 To 5 Do
  73.     For j:=1 To 5 Do
  74.       If (Length(cle)>longc) Then
  75.         Begin
  76.           longc := longc+1;
  77.           m[i,j] := cle[longc];
  78.         End
  79.       Else
  80.         Begin
  81.           Repeat
  82.             x := x+1;
  83.           Until (Pos(Chr(x+64),cle)=0) And (Chr(x+64)<>'W');
  84.           m[i,j] := Chr(x+64);
  85.         End;
  86.   ch1 := '';
  87.   For i:=1 To Length(msg) Do
  88.     If (msg[i]='W') Then
  89.       ch1 := ch1+recherche('V',m)
  90.     Else If (msg[i]=' ') Then
  91.            ch1 := ch1+' '
  92.     Else
  93.       ch1 := ch1+recherche(msg[i],m);
  94.   Assign (f,'c:\bac\Mess_Crypt.txt');
  95.   Rewrite (f);
  96.   Writeln (f,ch1);
  97.   Close (f);
  98. End;
  99. Begin
  100.   saisie (msg,cle);
  101.   traitement (m,msg,cle);
  102. End.
  103.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement