n
sonlari ishlatiladi.
Listing

n
sonlari ishlatiladi.
Listing
(S++
dasturlash tilida).
while(FLAG==l);
d = l;
do
{
s = (d*e)%phi;
d++;
}w h ile(s!-l);
d
=
d-1;
6-qadam.
Dastlabki axborotning fizik tabiatidan qat’iy nazar
raqamli ikkili ko'rinishda ifodalanadi. Bitltfr ketma-ketligi
L
bit
uzunlikdagi bloklarga ajratiladi, bu Herda
L-LAo%i(n+\)
shartini
qanoatlantiruvchi eng kichik butun son. Har bir blok [0,
n-
1] ora-
liqqa taalluqli butun musbat son kabi ko‘riladi. Shunday qilib, dast
labki axborot Д0» i=1,/ sonlaming ketma-ketligi orqali ifodalanadi.
/ ning qiymati shifrlanuvchi ketma-ketlikning uzunligi orqali
aniqlanadi.
7-qadam.
Shifrlangan axborot quyidagi formula bo‘yicha aniq-
lanuvchi
Y(i)
sonlaming ketma-ketligi ko‘rinishida olinadi:
Y(i) = ( X (f))e
(mod и).
Listing (S++ dasturlash tilida).
262
{
inti;
С = 1;
for(i=0;i
C=C*M%n;
С
=
C%n;
printf("\n\tShifrlanganso
‘z:
%d",C);
}
Axborotni rasshifrovka qilishda quyidagi munosabatdan foyda-
laniladi:
X( i )
= (7(;))‘, (mod«).
Listing (S++ dasturlash tilida).
voiddecryptQ
{
inti;
M
=
1;
for(i=0;i
M=M*C%n;
M
=
M%n;
printf("\n\tDeshifrlanganso ‘z : %d",M);
}
DES shifrlash algoritmining dasturiy amalga oshirilishi.
DES standartida dastlabki axborot 64 bitli bloklarga ajratiladi
va 56 yoki 64 bitli kalit yordamida kriptografik o‘zgartiriladi.
Dastlabki axborot bloklari o‘rin almashtirish va shifrlash funksiyala-
ri yordamida iteratsion ishlanadi. Shifrlash funksiyasini hisoblash
uchun 64 bitli kalitdan 48 bitligini olish, 32 bitli kodni 48 bitli kod-
ga kengaytirish, 6 bitli kodni 4 bitli kodga o‘zgartirish va 32 bitli
ketma-ketlikning o‘mini almashtirish ko‘zda tutilgan.
Rasshifrovka jarayoni shifrlash jarayoniga invers bo‘lib, shifr-
lashda ishlatiladigan kalit yordamida amalga oshiriladi.
263
voidencryptQ
Hozirda bu standart quyidagi ikkita sababga ko‘ra foydala-
nishga butunlay yaroqsiz hisoblanadi:
• kalitning uzunligi 56 bitni tashkil etadi, bu shaxsiy kompyu-
terlaming zamonaviy rivoji uchun juda kam;
• algoritm yaratilayotganida uning apparat usulda amalga
oshirilishi ko‘zda tutilgan edi, ya’ni algoritmda mikroprotsessorlar-
da bajarilishida ko‘p vaqt talab qiluvchi amallar bor edi (masalan,
mashina so‘zida ma’lum sxema bo‘yicha bitlaming o‘mini almash-
tirish kabi).
DES algoritmining dasturiy kodi:
• # include
• # include
• # include
• # include
• //Kalit kiritish j arayoni
• intkey[64]={
•
0
,
0
,
0
,
1
,
0
,
0
,
1
,
1
,
• 0,0,1,1,0,1,0,0,
• 0,1,0,1,0,1,1,1,
• 0,1,1,1,1,0,0,1,
•
1,0,0,1,1,0,
1
,
1
,
• 1,0,1,1,1,1,0,0,
• 1,1,0,1,1,1,1,1,
• 1,1,1,1,0,0,0,1
• };
• //Bloklarga ajratish jarayoni
• class Des
• {
• public:
• int keyi[16][48],
• total[64],
• left[32],
264
right[32],
ck[28],
dk[28],
expansion[48],
z[48],
xorl[48],
sub[32],
P[32],
xor2[32],
temp[64],
pci [56],
ip[64],
inv[8][8];
char final[ 1000];
void IP();
void PermChoicel();
void PermChoice2();
void Expansion();
void inverse();
void xor_two();
void xoroneE(int);
void xoroneD(int);
void substitution();
void permutation();
void keygen();
char * Encrypt(char *);
char * Decrypt(char *);
};
//Boshlang‘ich IP o‘zgartirish
void Des::IP() //Initial Permutation
{
int k=58,i;
for(i=0;i<32;i++)
265
• {
• ip[i]=total[k-l];
• if(k-8>0) k=k-8;
• else k=k+58;
• }
• k=57;
• for( i=32;i<64;i++)
• {
• ip[i]=total[k-l];
• if(k-8>0) k=k-8;
• else
k=k+58;
• }
• }
• void Des: :PermChoice 1 () //Permutation Choice-1
• {
• intk=57,i;
• for(i=0;i<28;i++)
• {
• pcl[i]=key[k-l];
• if(k-8>0) k=k-8;
• else
k=k+57;
• }
• k=63;
• for( i=28;i<52;i++)
• {
• pcl[i]=key[k-l];
• if(k-8>0) k=k-8;
• else
k=k+55;
• }
• k=28;
• for(i=52;i<56;i++)
• {
• pcl[i]=key[k-l];
266
• к=к-8;
• }
• }
• void Des: :Expansion() //Expansion Function applied on
'right' half
• {
• int exp[8][6],ij,k;
• for( i=0;i<8;i++)
• {
• for(j=0y<6y++)
• {
• if((j!=0)||(j!=5))
• {
• k=4*i+j;
• exp[i][j]=right[k-l];
• }
• if(j~ 0 )
• {
• k=4*i;
• exp[i][j]=right[k-l];
• }
|