38
{=== Matnni bosh harflar bilan yozish ======}
function Boshharf(Matn: string): string;
var
i: integer;
tmps:string;
xarf:char;
begin
tmps:='';
for i:=1 to length(Matn) do
begin
xarf:=chr(ord(Matn[i]));
tmps:=tmps+upcase(xarf);
end;
Boshharf:= tmps;
end;
{======================Shifrlangan harfga mos alfavit harfi raqamini
topish}
function Deshifr(n: byte):byte;
var i,j:integer;
begin
for i:=0 to d do
begin
j:=(a*i+b) mod(d+1);
if n=j then begin Deshifr:=i;break; end
else Deshifr:=d+1;
end;
end;
{======================Matn harfga mos alfavit harfi raqamini topish}
function LotCharToInt(ch: string):byte;
var i:integer;
begin
for i:=0 to d do
39
if ch=S[i] then begin LotCharToInt:=i;break; end
else LotCharToInt:=d+1;
end;
{=======================Affin kriptotizimi orqali shifrlash======}
BEGIN
CLRSCR;
write('Birinchi tub sonni kiriting ='); readln(a);
write('Ikkinchi tub sonni kiriting ='); readln(b);
write('Shifrlangan matnni kiriting='); readln(strok);
TextColor(4);
writeln; writeln('DESHIFRLASH');writeln;
writeln('Shifrlanadigan soz:');writeln;
TextColor(1);
writeln(strok);writeln;
{strok suzidagi harflarni bosh harflarga almashtirish}
dshifr:='';
s2:=Boshharf(strok);
kol:=length(strok);
for i:=1 to kol do
begin
s1:=copy(s2,i,1);
id:=LotCharToInt(s1); {harfning alfavitdagi ornini aniqlash}
j:=Deshifr(id); {shifr raqamiga mos matn raqamini aniqlash}
if j=d+1 then dshifr:=dshifr+s1
else dshifr:=dshifr+S[j];
end;
TextColor(4);
writeln('Deshifrlangan soz:');writeln;
TextColor(1);
writeln(dshifr);
{ readln;}
end.