SHOW:
|
|
- or go back to the newest paste.
| 1 | - | program Cryptage; |
| 1 | + | Program Cryptage; |
| 2 | - | uses wincrt; |
| 2 | + | Uses Wincrt; |
| 3 | - | type |
| 3 | + | Type |
| 4 | - | mat=array[1..20,1..10]of char; |
| 4 | + | mat = Array[1..20,1..10] Of Char; |
| 5 | - | var |
| 5 | + | Var |
| 6 | - | f,fcr:text; |
| 6 | + | f,fcr: Text; |
| 7 | - | cle:string; |
| 7 | + | cle: String; |
| 8 | - | m:mat; |
| 8 | + | m: mat; |
| 9 | - | l:integer; |
| 9 | + | l: Integer; |
| 10 | - | function verif(ch:string):boolean; |
| 10 | + | |
| 11 | - | var |
| 11 | + | Function verif(ch:String): Boolean; |
| 12 | - | i:integer; |
| 12 | + | Var |
| 13 | - | begin |
| 13 | + | i: Integer; |
| 14 | - | i:=1; |
| 14 | + | Begin |
| 15 | - | while(i<=length(ch)) and (ch[i] in ['A'..'Z']) do |
| 15 | + | i := 1; |
| 16 | - | i:=i+1; |
| 16 | + | While (i<=Length(ch)) And (ch[i] In ['A'..'Z']) Do |
| 17 | - | verif:=i>length(ch); |
| 17 | + | i := i+1; |
| 18 | - | end; |
| 18 | + | verif := i>Length(ch); |
| 19 | - | function distinct(ch:string):boolean; |
| 19 | + | End; |
| 20 | - | var |
| 20 | + | |
| 21 | - | v:boolean; |
| 21 | + | Function distinct(ch:String): Boolean; |
| 22 | - | i:integer; |
| 22 | + | Var |
| 23 | - | begin |
| 23 | + | v: Boolean; |
| 24 | - | i:=1; |
| 24 | + | i: Integer; |
| 25 | - | repeat |
| 25 | + | Begin |
| 26 | - | i:=i+1; |
| 26 | + | i := 1; |
| 27 | - | v:=pos(ch[i],copy(ch,1,i-1))=0; |
| 27 | + | Repeat |
| 28 | - | until not(v) or (i=length(ch)); |
| 28 | + | i := i+1; |
| 29 | - | distinct:=v; |
| 29 | + | v := Pos(ch[i],Copy(ch,1,i-1))=0; |
| 30 | - | end; |
| 30 | + | Until Not(v) Or (i=Length(ch)); |
| 31 | - | procedure saisie( var cle:string); |
| 31 | + | distinct := v; |
| 32 | - | begin |
| 32 | + | End; |
| 33 | - | repeat |
| 33 | + | |
| 34 | - | write('saisir un mot cle constituee de lettres majuscules distinctes de longueur entre 5 et 10 : ');
|
| 34 | + | Procedure saisie( Var cle:String); |
| 35 | - | readln(cle); |
| 35 | + | Begin |
| 36 | - | until (length(cle)>=5) and (length(cle)<=10) and (verif(cle)) and (distinct(cle)); |
| 36 | + | Repeat |
| 37 | - | end; |
| 37 | + | Write( |
| 38 | - | procedure rempm(var m:mat;var fcr:text;i:integer;var l:integer); |
| 38 | + | 'saisir un mot cle constituee de lettres majuscules distinctes de longueur entre 5 et 10 : ' |
| 39 | - | var |
| 39 | + | ); |
| 40 | - | j,c:integer; |
| 40 | + | Readln(cle); |
| 41 | - | ch:string; |
| 41 | + | Until (Length(cle)>=5) And (Length(cle)<=10) And (verif(cle)) And (distinct(cle)); |
| 42 | - | begin |
| 42 | + | End; |
| 43 | - | reset(fcr); |
| 43 | + | |
| 44 | - | l:=1; |
| 44 | + | Procedure rempm(Var m:mat;Var fcr:Text;i:Integer;Var l:Integer); |
| 45 | - | while not eof(fcr) do |
| 45 | + | Var |
| 46 | - | begin |
| 46 | + | j,c: Integer; |
| 47 | - | readln(fcr,ch); |
| 47 | + | ch: String; |
| 48 | - | while(i mod (length(ch))<>0) do |
| 48 | + | Begin |
| 49 | - | ch:=ch+' '; |
| 49 | + | Reset(fcr); |
| 50 | - | for j:=1 to length(ch) do |
| 50 | + | l := 1; |
| 51 | - | begin |
| 51 | + | While Not Eof(fcr) Do |
| 52 | - | for c:= 1 to i do |
| 52 | + | Begin |
| 53 | - | begin |
| 53 | + | Readln(fcr,ch); |
| 54 | - | m[c,l]:=ch[j]; |
| 54 | + | While (i Mod (Length(ch))<>0) Do |
| 55 | - | if (c=i) then |
| 55 | + | ch := ch+' '; |
| 56 | - | l:=l+1; |
| 56 | + | For j:=1 To Length(ch) Do |
| 57 | - | end; |
| 57 | + | Begin |
| 58 | - | end; |
| 58 | + | For c:= 1 To i Do |
| 59 | - | end; |
| 59 | + | Begin |
| 60 | m[c,l] := ch[j]; | |
| 61 | - | end; |
| 61 | + | If (c=i) Then |
| 62 | - | procedure crypter(var m:mat;var fcr,f:text;cle:string;var l:integer); |
| 62 | + | l := l+1; |
| 63 | - | begin |
| 63 | + | End; |
| 64 | - | reset(fcr); |
| 64 | + | End; |
| 65 | - | rewrite(f); |
| 65 | + | End; |
| 66 | - | rempm(m,fcr,length(cle),l); |
| 66 | + | Close(fcr); |
| 67 | - | close(fcr); |
| 67 | + | End; |
| 68 | - | close(f); |
| 68 | + | |
| 69 | - | end; |
| 69 | + | Procedure crypter(Var m:mat;Var fcr,f:Text;cle:String;Var l:Integer); |
| 70 | - | procedure affiche(var f:text); |
| 70 | + | Begin |
| 71 | - | var |
| 71 | + | Rewrite(f); |
| 72 | - | ch:string; |
| 72 | + | rempm(m,fcr,Length(cle),l); |
| 73 | - | begin |
| 73 | + | Close(f); |
| 74 | - | reset(f); |
| 74 | + | End; |
| 75 | - | while (not(eof(f))) do |
| 75 | + | |
| 76 | - | begin |
| 76 | + | Procedure affiche(Var f:Text); |
| 77 | - | readln(f,ch); |
| 77 | + | Var |
| 78 | - | writeln(ch); |
| 78 | + | ch: String; |
| 79 | - | end; |
| 79 | + | Begin |
| 80 | - | close(f); |
| 80 | + | Reset(f); |
| 81 | - | end; |
| 81 | + | While (Not(Eof(f))) Do |
| 82 | - | procedure affmat(m:mat;l,c:integer); |
| 82 | + | Begin |
| 83 | - | var |
| 83 | + | Readln(f,ch); |
| 84 | - | i,j:integer; |
| 84 | + | Writeln(ch); |
| 85 | - | begin |
| 85 | + | End; |
| 86 | - | for i:= 1 to l do |
| 86 | + | Close(f); |
| 87 | - | begin |
| 87 | + | End; |
| 88 | - | for j:= 1 to c do |
| 88 | + | |
| 89 | - | writeln(m[l,c]); |
| 89 | + | Procedure affmat(m:mat;l,c:Integer); |
| 90 | - | end; |
| 90 | + | Var |
| 91 | - | end; |
| 91 | + | i,j: Integer; |
| 92 | Begin | |
| 93 | - | begin |
| 93 | + | For i:= 1 To l Do |
| 94 | - | assign(fcr,'C:\BAC2020\Sources.txt'); |
| 94 | + | Begin |
| 95 | - | assign(f,'C:\BAC2020\Crypt.txt'); |
| 95 | + | For j:= 1 To c Do |
| 96 | - | saisie(cle); |
| 96 | + | Writeln(m[l,c]); |
| 97 | - | crypter(M,fcr,f,cle,l); |
| 97 | + | End; |
| 98 | - | affmat(m,l,length(cle)); |
| 98 | + | End; |
| 99 | - | affiche(f); |
| 99 | + | Begin |
| 100 | - | end. |
| 100 | + | assign(fcr,'C:\Users\platpot\Desktop\arfizato\progg\pascal\Projects\Source.txt'); |
| 101 | assign(f,'C:\Users\platpot\Desktop\arfizato\progg\pascal\Projects\Crypt.txt'); | |
| 102 | ReWrite(fcr); | |
| 103 | close(fcr); | |
| 104 | saisie(cle); | |
| 105 | crypter(M,fcr,f,cle,l); | |
| 106 | affmat(m,l,Length(cle)); | |
| 107 | affiche(f); | |
| 108 | End. |