Repository navigation
Expand file tree
/
Copy pathKoderAlg2.cpp
More file actions
112 lines (90 loc) · 1.7 KB
/
Copy pathKoderAlg2.cpp
File metadata and controls
112 lines (90 loc) · 1.7 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include "stdafx.h"
#include "KoderAlg2.h"
void CKoderAlg2::Crypt(string text, int dlugosc)
{
clock_t start,start2,stop2, stop;
double czas,czas2;
start=clock();
string litery[123][123];
int alfabet=0,pp=0;
for(int i=0;i<123;i++)
{
for(int j=0;j<123;j++)
{
litery[i][j]='*';
}
}
for(int i=65;i<91;i++)
{
alfabet=64;
pp=i-alfabet;
alfabet+=pp;
if(alfabet==91)
alfabet=65;
for(int j=65;j<91;j++)
{
if(alfabet==91)
alfabet=65;
litery[i][j]=alfabet;
alfabet ++;
}
}
for(int i=97;i<123;i++)
{
alfabet=96;
pp=i-alfabet;
alfabet+=pp;
if(alfabet==123)
alfabet=97;
for(int j=97;j<123;j++)
{
if(alfabet==123)
alfabet=97;
litery[i][j]=alfabet;
alfabet ++;
}
}
klucz.clear();
koniec.clear();
stop=clock();
do
{
cout<<endl<<"Podaj slowo klucz"<<endl;
cin>>klucz;
if(klucz.size()==dlugosc+1)
cout<<"Za dlugie slowo klucz!"<<endl;
}while(klucz.size()==dlugosc+1);
start2=clock();
int literka1=0, literka2=0, zerowanie=0; //tu mieszalem
for(int i=0;i<dlugosc;i++)
{
if (text[i]==32)
{
koniec.append(" ");
continue;
}
if(text[i]>96 && klucz[zerowanie]<96)
klucz[zerowanie]+=32;
else if(text[i]<91 && klucz[zerowanie]>91)
klucz[zerowanie]-=32;
literka1=text[i];
literka2=klucz[zerowanie];
koniec.append(litery[literka1][literka2]);
zerowanie++;
if(zerowanie==klucz.size() )
zerowanie=0;
}
stop2=clock();
czas=(double)(stop-start)/CLOCKS_PER_SEC;
czas2=(double)(stop2-start2)/CLOCKS_PER_SEC;
cout<<"Czas trwania algorytmu: "<<czas<<" i "<<czas2<<endl;
Sleep(1000);
}
CKoderAlg2::CKoderAlg2()
{
klucz="default";
koniec="default";
}
CKoderAlg2::~CKoderAlg2(void)
{
}