Repository navigation
Expand file tree
/
Copy pathmenu.cpp
More file actions
336 lines (281 loc) · 8.1 KB
/
Copy pathmenu.cpp
File metadata and controls
336 lines (281 loc) · 8.1 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
#include "szyfrowanie.h"
using namespace std;
Menu::Menu()
{
}
Menu::~Menu()
{
}
void Menu::menu()
{
plik=fopen("temp.txt","rt");
//unsigned char wybor=0, tryb=0;
fscanf(plik,"Poczatek: %d\n", &poczatek);
fscanf(plik,"Tryb: %d\n", &tryb);
fscanf(plik,"Metoda: %d\n", &metoda);
/*if(tryb==0)
{
FPGA();
}*/
/*
printf("\n\n");
printf("����������������");
printf("\n\n");
printf("Jakiego rodzaju test chcesz wykonac?\n");
printf("0 - hellman 16 bitowy\n");
printf("1 - rivest 16 bitowy\n");
printf("2 - teczowa 16 bitowy\n");
printf("3 - hellman 32 bitowy\n");
printf("4 - rivest 32 bitowy\n");
printf("5 - teczowa 32 bitowy\n");
scanf("%d", &wybor);*/
switch (metoda)
{
case 1:
hell16();
break;
case 2:
rive16();
break;
case 3:
tecz16();
break;
case 4:
hell32();
break;
case 5:
rive32();
break;
case 6:
tecz32();
break;
case 7:
FPGA();
break;
}
}
void Menu::FPGA()
{
FILE* FPGAin;
unsigned short pom, klucz;
klucz=0x0fac;
char wynik[4];
unsigned char pobrane[4];
bool flagapobrania=0;
char nazwa[4]="COM";
unsigned short numer;
fscanf(plik,"Zmienna: %d\n", &pom);
fscanf(plik,"t: %d\n", &pom);
fscanf(plik,"m: %d\n", &pom);
fscanf(plik,"r: %d\n", &pom);
fscanf(plik,"Plaintext: %x\n", &plaintext);
fscanf(plik,"COM: %s\n",&nazwa[3]);
fclose(plik);
FPGAin=fopen("wyjsciowe.txt","wt");
konfiguracjaportu.BaudRate=9600;
konfiguracjaportu.StopBits=ONESTOPBIT;
konfiguracjaportu.Parity=PARITY_ODD;
konfiguracjaportu.ByteSize=DATABITS_8;
serialport = CreateFile(nazwa,GENERIC_READ | GENERIC_WRITE,0,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);
//petla start
cout<<plaintext<<endl;
sprintf(wynik,"%x",plaintext);
WriteFile(serialport,wynik,4,&wyslanebajty,NULL);
WriteFile(serialport,"x",1,&wyslanebajty,NULL);
printf("%x\n",plaintext);
szyfrowanie16(plaintext,klucz,pom);
sprintf(wynik,"%x",pom);
cout<<wynik<<endl;
WriteFile(serialport,wynik,4,&wyslanebajty,NULL);
WriteFile(serialport,"x",1,&wyslanebajty,NULL);
plaintext = plaintext^0x00ff;
szyfrowanie16(plaintext,klucz,pom);
sprintf(wynik,"%x",pom);
cout<<wynik<<endl;
WriteFile(serialport,wynik,4,&wyslanebajty,NULL);
WriteFile(serialport,"x",1,&wyslanebajty,NULL);
plaintext = plaintext ^ 0xffff;
szyfrowanie16(plaintext,klucz,pom);
sprintf(wynik,"%x",pom);
cout<<wynik<<endl;
WriteFile(serialport,wynik,4,&wyslanebajty,NULL);
WriteFile(serialport,"x",1,&wyslanebajty,NULL);
while(pobrane[0]==NULL)
{
flagapobrania=ReadFile(serialport,&pobrane[0],1,&odebranebajty,NULL);
}
flagapobrania=ReadFile(serialport,&pobrane[1],1,&odebranebajty,NULL);
flagapobrania=ReadFile(serialport,&pobrane[2],1,&odebranebajty,NULL);
flagapobrania=ReadFile(serialport,&pobrane[3],1,&odebranebajty,NULL);
printf("%x\n%x\n%x\n%x\n",(pobrane[0]-1),(pobrane[1]-1),(pobrane[2]-1),(pobrane[3]-1));
fprintf(FPGAin,"%x%x%x%x",(pobrane[3]-1),(pobrane[2]-1),(pobrane[1]-1),(pobrane[0]-1));
fclose(FPGAin);
CloseHandle(serialport);
}
void Menu::hell16()
{
hellman16 h16;
h16.menuHellmanZapis(this);
}
void Menu::rive16()
{
rivest16 r16;
r16.menuRivestZapis(this);
}
void Menu::tecz16()
{
teczowa16 t16;
t16.menuTeczowaZapis(this);
}
void Menu::hell32()
{
hellman32 h32;
h32.testowyMenuHellmanZapis(this);
}
void Menu::rive32()
{
rivest32 r32;
r32.menuRivestZapis(this);
}
void Menu::tecz32()
{
teczowa32 t32;
t32.menuTeczowaZapis(this);
}
/*
void menu()
{
unsigned char wybor=0;
fscanf(plik,"Metoda: %d\n", &wybor);
printf("\n\n------------------\n\n");
printf("Co robic? \n 0 - Tworz jedna tablice\n 1 - Szukaj klucza\n 2 - Zapisz tabele do pliku\n 3 - Wiele tablic metoda Hellmana\n 4 - Statystyka wielu tablic Hellmana\n 5 - Hellman, 16-bitowe zmienne\n 6 - Rivest, 16-bitowe zmienne\n 7 - Oechslin, 16-bitowe zmienne\n");
printf(" 8 - Test czasu\n");
scanf("%d", &wybor);
hellman16 hel16;
rivest16 riv16;
teczowa16 tecz16;
hellman32 hel32;
rivest32 riv32;
teczowa32 tecz32;
unsigned int blabla=0x1f2f4f;
switch (wybor)
{
case 5:
hel16.menuHellmanZapis();
break;
case 6:
riv16.menuRivestZapis();
break;
case 7:
tecz16.menuTeczowaZapis();
break;
case 8:
int czas[6];
czas[0]=hel16.testCzasuLamania();
czas[1]=hel16.testCzasuTworzenia();
czas[2]=riv16.testCzasuLamania();
czas[3]=riv16.testCzasuTworzenia();
czas[4]=tecz16.testCzasuLamania();
czas[5]=tecz16.testCzasuTworzenia();
printf("Czas tworzenia tablicy hellmana to %d, a lamania to %d\n",czas[1],czas[0]);
printf("Czas tworzenia tablicy rivesta to %d, a lamania to %d\n",czas[3],czas[2]);
printf("Czas tworzenia tablicy teczowej to %d, a lamania to %d\n",czas[5],czas[4]);
break;
case 9:
printf("Czas lamania rivesta32 to %d\n",riv32.testCzasuLamania());
break;
case 10:
int czas1[6];
czas1[0]=hel32.testCzasuLamania();
czas1[1]=hel32.testCzasuTworzenia();
printf("Czas tworzenia tablicy hellmana to %d, a lamania to %d\n",czas1[1],czas1[0]);
czas1[2]=riv32.testCzasuLamania();
czas1[3]=riv32.testCzasuTworzenia();
printf("Czas tworzenia tablicy rivesta to %d, a lamania to %d\n",czas1[3],czas1[2]);
czas1[4]=tecz32.testCzasuLamania();
czas1[5]=tecz32.testCzasuTworzenia();
printf("Czas tworzenia tablicy teczowej to %d, a lamania to %d\n",czas1[5],czas1[4]);
break;
case 11:
printf("Czas tworzenia tablicy rivesta to %d, a lamania to %d\n",riv32.testCzasuTworzenia(),riv32.testCzasuLamania());
break;
case 12:
tecz32.tworz(256,256*256,0x20202020);
printf("\nTrafienia teczowej: %d \n",tecz32.statystyka());
hel32.tworz(256,256,256,0x20202020); //1626
printf("\nTrafienia hellmana: %d \n",hel32.statystyka());
riv32.tworz(40000,256,256,0x20202020, (0xFFFFFFFF << (32 - 14)));
printf("\nTrafienia rivesta: %d \n",riv32.statystyka());
break;
case 13:
riv32.tworz(40000,1626,1626,0x20202020, (0xFFFFFFFF << (32 - 14)));
printf("\nSrednia dlugosc lancucha to: %d\n",riv32.getSredniT());
break;
case 14:
hel32.menuHellmanZapis();
break;
case 15:
riv32.menuRivestZapis();
break;
case 16:
tecz32.menuTeczowaZapis();
break;
case 17:
hel32.testowyMenuHellmanZapis();
break;
}
}
*/
void czytoten( int pozycja)
{
}
void Menu::upStan()
{
FILE* output;
output=fopen("temp.txt","wt");
fprintf(output,"Poczatek: %d\n", poczatek);
fprintf(output,"Tryb: %d\n", tryb);
fprintf(output,"Metoda: %d\n", metoda);
fprintf(output,"Zmienna: %d\n", zmienna);
fprintf(output,"t: %d\n", t);
fprintf(output,"m: %d\n", m);
fprintf(output,"r: %d\n", r);
fprintf(output,"Plaintext: %d\n", plaintext);
fprintf(output,"Seed: %d\n", seed);
fprintf(output,"Finalna: %d\n", finalna);
fprintf(output,"Krok: %d\n", krok);
fprintf(output,"Testy: %d\n", testy);
fprintf(output,"Zera: %d\n", t);
fprintf(output,"Tablica: %d\n", t);
fprintf(output,"Wykonano: %d\n", wykonano);
fclose(output);
}
void Menu::started(unsigned int p,unsigned int s,unsigned int f,unsigned int k, unsigned int ze, unsigned int ta, unsigned int te, unsigned int zm)
{
poczatek=1;
plaintext=p;
seed=s;
finalna=f;
krok=k;
testy=te;
zera=ze;
tablica=ta;
zmienna=zm;
}
bool Menu::getPoczatek()
{
return poczatek;
}
unsigned int Menu::getWykonano()
{
return wykonano;
}
void Menu::update(int dt, int dm, int dr, int dseed, int dwykonano)
{
t=dt;
m=dm;
r=dr;
seed=dseed;
wykonano=dwykonano;
upStan();
}