4-amaliy mashg’ulot
Mavzu: Kriptografiyaga kirish
4
|
14
|
15
|
1
|
9
|
7
|
6
|
12
|
5
|
11
|
10
|
8
|
16
|
2
|
3
|
13
|
Boshlang’ich matn sifatida quyidagi matnni olamiz:
T0=ALIJONOVIBRATJON
Ushbu ochiq matn elementlarini jadvalga tartib bilan joylashtiramiz:
J
|
J
|
O
|
A
|
I
|
O
|
N
|
A
|
O
|
R
|
B
|
V
|
N
|
L
|
I
|
T
|
3. Shifrlangan matn jadval elementlarini satrlar bo’yicha o’qish natijasida hosil qilinadi.
T1=JJOA IONA ORBV NLIT
5-amaliy mashg’ulot
Klassik shifrlar. Sezar va Vijener algoritmi
Ishdan maqsad: Shifrlash algoritmlari bilan tanishish, sezar va Vijener algoritmlari haqida ma’lumotga ega bo’lish
SEZAR ALGORITMI
DASTUR KODI
// A C++ program to illustrate Caesar Cipher Technique
#include
using namespace std;
// This function receives text and shift and
// returns the encrypted text
string encrypt(string text, int s)
{
string result = "";
// traverse text
for (int i=0;i
{
// apply transformation to each character
// Encrypt Uppercase letters
if (isupper(text[i]))
result += char(int(text[i]+s-65)%26 +65);
// Encrypt Lowercase letters
else
result += char(int(text[i]+s-97)%26 +97);
}
// Return the resulting string
return result;
}
// Driver program to test the above function
int main()
{
string text="ULUGBEK";
int s = 4;
cout << "Text : " << text;
cout << "\nShift: " << s;
cout << "\nCipher: " << encrypt(text, s);
return 0;
}
2. VijEner usulida axborotni shifrlash.
1. Alfavitni belgilab olamiz.
DASTUR KODI
#include
#include
#include
using namespace std;
int main(){
int i,j,k,n;
vectorchar> > a(26,vector<char>(26));
k=0;
n=26;
for(i=0;i
k=i;
for(j=0;ja[i][j]='A'+k;
k++;
if(k==26)
k=0;
}
}
cout<<"Enter the message\n";
string s;
cin>>s;
cout<<"Enter the key\n";
string key;
cin>>key;
k=0;
int mod = key.size();
for(i=key.size();ikey+=key[k%mod];
k++;
}
string encrypt;
for(i=0;i
encrypt+= a[s[i]-'A'][key[i]-'A'];
}
cout<<"Encrypted message: "<
return 0;
}
6-AMALIY ISH
M=ALIJONOV_IBRATJON
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
|
_
|
Z
|
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
|
26
|
25
|
A
|
L
|
I
|
J
|
O
|
N
|
O
|
V
|
_
|
I
|
B
|
R
|
A
|
T
|
J
|
O
|
N
|
0
|
11
|
8
|
9
|
14
|
13
|
14
|
21
|
26
|
8
|
1
|
17
|
0
|
19
|
9
|
14
|
13
|
N=26
A=3
B=5
M=(a*t+b)modn
M(0)=(3*0+5)mod26=5
M(11)=(3*11+5)mod26=10
M(8)=(3*8+5)mod26=3
M(9)=(3*9+5)mod26=6
M(14)=(3*14+5)mod26=21
M(13)=(3*13+5)mod26=18
M(14)=(3*14+5)mod26=21
M(21)=(3*21+5)mod26=16
M(26)=(3*26+5)mod26=5
M(8)=(3*8+5)mod26=3
M(1)=(3*1+5)mod26=8
M(17)=(3*17+5)mod26=4
M(0)=(3*0+5)mod26=5
M(19)=(3*19+5)mod26=10
M(9)=(3*9+5)mod26=6
M(14=(3*14+5)mod26=21
M(13)=(3*13+5)mod26=18
M(sh)=F,K,D,G,V,S,V,Q,F,D,I,E,F,K,J,V,S
Mdsh(t) = (a-1)*(t+n-b) ( mod n )
Shifr matn
|
F
|
K
|
D
|
G
|
V
|
S
|
V
|
Q
|
F
|
D
|
I
|
E
|
F
|
K
|
J
|
V
|
S
|
t(tartib raqami)
|
5
|
10
|
3
|
6
|
21
|
18
|
21
|
16
|
5
|
3
|
8
|
4
|
5
|
10
|
6
|
21
|
18
|
9*(t +26- 4)
|
156
|
288
|
225
|
252
|
387
|
360
|
387
|
342
|
243
|
225
|
270
|
0
|
243
|
288
|
252
|
387
|
360
|
9*(t+26-4) (mod 26)
|
0
|
11
|
8
|
9
|
14
|
13
|
14
|
21
|
26
|
8
|
1
|
17
|
0
|
9
|
19
|
14
|
13
|
Ochiq matn
|
A
|
L
|
I
|
J
|
O
|
N
|
O
|
V
|
_
|
I
|
B
|
R
|
A
|
T
|
J
|
O
|
N
|
Dostları ilə paylaş: |