0 | 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 |
A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z |
program encode_base;
uses crt;
var a,b,c:string;
n,aa:integer;
function encode(strd,bang:string;add:integer):string;
var ab,bb,cb:integer;
begin
for ab:=1 to length(strd) do begin
cb:=0;
for bb:=1 to length(bang) do begin
if strd[ab]=bang[bb] then begin
cb:=bb;
break;
end;
end;
if cb<>0 then begin
if (cb+add)<=length(bang) then strd[ab]:=bang[cb+add] else strd[ab]:=bang[(cb+add) mod length(bang)];
end;
end;
encode:=strd;
end;
function decode(strd,bang:string;add:integer):string;
var ab,bb,cb:integer;
begin
for ab:=1 to length(strd) do begin
cb:=0;
for bb:=1 to length(bang) do begin
if strd[ab]=bang[bb] then begin
cb:=bb;
break;
end;
end;
if cb<>0 then begin
if (cb-add)>0 then strd[ab]:=bang[cb-add] else strd[ab]:=bang[cb + length(bang) - add];
end;
end;
decode:=strd;
end;
begin
aa:=7;
a:='ABCDEFGHIJKLMNOPQRSTUVWXYZ';
writeln('Chon ma hoa hay giai ma bro? encode/decode => ');
readln(b);
if b='encode' then begin
writeln('nhap ky tu can ma hoa bro => ');
readln(c);
writeln('encode => ',encode(c,a,aa));
end else begin
if b='decode' then begin
readln(c);
writeln('decode => ',decode(c,a,aa));
end else writeln('toi da noi la dien encode hoac decode, toi ve nha ong khong nghiem tuc ti nao ca');
end;
readln
end.