Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //https://www.kiteb.net/education/informatique/bac/bacinfo2014/bac-pratique-22052014-algo-14h.pdf
- program AyaSahbiSkon;
- uses WinCrt;
- Type
- mat = Array [1..5,0..5] of char;
- var
- m : mat ;
- l : byte ;
- cle,msg: string;
- Procedure clean( var cle : string);
- var
- a : byte;
- begin
- for a:=Length(cle) DownTo 1 do
- if pos(cle[a],cle) <> a then
- delete(cle,a,1);
- end;
- Procedure remp(var m : mat ; cle: string);
- var
- a,b : byte;
- begin
- clean(cle);
- for a:=1 to Length(cle) do
- if (a mod 5 <> 0) then
- m[a div 5+1, a mod 5]:=cle[a]
- else
- m[a div 5, 5]:=cle[a];
- b:= ord('A');
- while (a<=25) do
- begin
- if (pos(chr(b),cle) <>0 ) or (chr(b) = 'W') then
- b:=b+1
- else
- Begin
- if (a mod 5 <> 0) then
- m[a div 5+1, a mod 5]:=chr(b)
- else
- m[a div 5, 5]:=chr(b);
- a:=a+1;
- b:=b+1;
- end;
- end;
- end;
- Function position(c:char ; m : mat): string;
- var
- a,b: byte ;
- ch: string;
- begin
- a:=1;
- b:=1;
- if c = ' ' then
- ch:= c
- else if c= 'W' then
- ch:=position('V',m)
- else
- begin
- while m[a,b] <> Upcase(c) do
- begin
- b:=b+1;
- if b= 6 then
- begin
- b:=1;
- a:=a+1;
- end;
- end;
- ch:=chr(ord('0')+a)+ chr(ord('0')+b) ;
- end;
- position:=ch;
- end;
- function crypt(msg: String; m :mat): string;
- var
- a : byte;
- ch : String;
- begin
- ch:='';
- for a:=1 to Length(msg) do
- ch:=ch+position(msg[a],m);
- crypt := ch;
- end;
- begin
- readln(msg);
- readln(cle);
- remp(m,cle);
- writeln(crypt(msg,m));
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement