Elaborati un program in PASCAL care codifica si decodifica literele alfabetului latin.Se va utiliza codul propus de Francis Bacon.
Răspunsuri la întrebare
Salut, sa iti fie de folos. L-am facut in Pascal. Poate poti sa il mai cureti umpic.
program da;
var a:array['A'..'Z'] of String;
i,j:Integer;
iIndex:Char;
s,s1,tempS2,s2:String;
tempChar: Char;
begin
s:='Ana are mere.';
s1:='';
a['A']:= 'aaaaa';
a['B']:= 'aaaab';
a['C']:= 'aaaba';
a['D']:= 'aaabb';
a['E']:= 'aabaa';
a['F']:= 'aabab';
a['G']:= 'aabba';
a['H']:= 'aabbb';
a['I']:= 'abaaa';
a['J']:= 'abaab';
a['K']:= 'ababa';
a['L']:= 'ababb';
a['M']:= 'abbaa';
a['N']:= 'abbab';
a['O']:= 'abbba';
a['P']:= 'abbbb';
a['Q']:= 'baaaa';
a['R']:= 'baaab';
a['S']:= 'baaba';
a['T']:= 'baabb';
a['U']:= 'babaa';
a['V']:= 'babab';
a['W']:= 'babba';
a['X']:= 'babbb';
a['Y']:= 'bbaaa';
a['Z']:= 'bbaab';
//Criptare
for i:=1 to length(s) do
begin
if (s[i] = ' ') then
s1:=s1+' '
else if (s[i]='.') then
s1:=s1+'.'
else
begin
tempChar := s[i];
if((tempChar >= 'a') AND (tempChar <= 'z')) then
tempChar:=chr(ord(s[i]) - 32);
s1:= s1 + a[tempChar];
end;
end;
writeln('Sir initial: ', s);
Writeln('Sir cryptat: ', s1);
//Decriptare
j:=1;
while(j<=length(s1)) do
begin
if not(s1[j]=' ') then
begin
tempS2:='';
tempS2:= tempS2+s1[j];
tempS2:= tempS2+s1[j+1];
tempS2:= tempS2+s1[j+2];
tempS2:= tempS2+s1[j+3];
tempS2:= tempS2+s1[j+4];
for iIndex:='A' to 'Z' do
if(a[iIndex] = tempS2) then
begin
s2:=s2+iIndex;
break;
end;
j+=5;
end
else
begin
s2:=s2+s1[j];
inc(j);
end;
end;
s2:=s2+s1[length(s1)];
Write('Sir decryptat:', s2);
end.