Code Pascal : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
program Cryptage;
uses wincrt;
var M:String;
p:integer ;
Function valide(M:string):boolean;
Var i:integer;
ok:boolean;
begin
ok:=true;
if m='' then ok:=false
Else
Begin
i:=0;
 
Repeat
 i:=i+1;
 if not (M[i] in [' ','A'..'Z','a'..'z']) then ok:=false;
until (ok=false) or (i=Length(M))
end;
valide:=ok;
end;
Procedure saisir(var M:string);
Begin
Repeat
write('Donner le message à crypter : ');
readln(M);
until valide(M);
end;
function nbmot(M:string):integer;
Var    i,nb:integer;
Begin
i:=0;  nb:=0;
Repeat
 i:=i+1;   
if  (upcase(M[i]) in ['A'..'Z']) then nb:=nb+1;
 
 while (i<=length(m)) and (upcase(M[i]) in ['A'..'Z']) do
 i:=i+1;
until (i>=length(M));
 
nbmot:=nb;
end;
 
function Crypter(M:string; p:integer):string;
Var     code,i:Integer;
Begin
 for i:=1 to Length(M) Do
	Begin
	code:= ord(M[i])+p;
 if M[i] in ['a'..'z'] then if code>ord('z') then   code:=code-26;
  if M[i] in ['A'..'Z'] then if code>ord('Z') then   code:=code-26;
 if M[i]<>' ' then M[i]:=chr(code);
 end;
crypter:=M;
end;
 
Begin
saisir(M);
p:=Nbmot(M);
writeln(p);
WriteLn(Crypter(M,p)); 
end.