K(/) = (* ( /)) '(mod «).
Listing (5++ dasturlash tilida).
262
voidencryptQ
{
inti;
C = 1;
for(i=0;i
C=C*M%n;
C = C%n;
printf("\n\tShifrlanganso z: %d",C');
}
Axborotni rasshifrovka qilishda quyidagi munosabatdan foyda-
laniladi:
*(0 = 040)''(mod/O-
Listing (S++ dasturlash tilida).
voiddecrypt()
{
inti;
M = I;
for(i=0;i
M=M*C%n;
M = M%n;
printf("\n\tDeshifrlanganso'z: %d",M);
}
D E S shifrlash algoritm in ing d astu riy am alga 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
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 m a’lum sxema bo‘yicha bitlaming o ‘mini almash-
tirish kabi).
DES algoritmining dasturiy kodi:
• # include
• # include
• # include
• # include
• //Kalit kiritish jarayoni
• int key[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],
2 6 4
• 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 xor oneE(int);
• void xor oneD(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++)
26 5
• {
• 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::PermChoicel() //Permutation Choice-1
• (
• int k=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++)
• {
• pc 1 [i]=key[k-1 ];
• if(k-8>0) k=k-8;
• else
k=k+55;
• }
• k=28;
• for(i=52;i<56;i++)
• {
• pc 1 [i]=key[k-1 ];
2 6 6
|