-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
executable file
·60 lines (50 loc) · 1.16 KB
/
test.cpp
File metadata and controls
executable file
·60 lines (50 loc) · 1.16 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
#include "test.h"
void test()
{
const int key_size = 512;
char publ_file[] = "test_public_key";
char priv_file[] = "test_priv_key";
char middle_file[] = "test_middle_key";
char infile[] = "test_infile";
char outfile[] = "test_outfile";
generate_keys(key_size, publ_file, priv_file);
encryption(infile, middle_file, publ_file);
decryption(middle_file, outfile, priv_file);
compare_files(infile, outfile);
}
int compare_files(char* infile, char* outfile)
{
FILE *f1;
FILE *f2;
char buf1;
char buf2;
f1 = fopen( infile, "rt" );
if (f1 == NULL)
{
printf("No such file!\n");
return 0;
}
f2 = fopen( outfile, "rt" );
if (f2 == NULL)
{
printf("No such file!\n");
return 0;
}
while (!feof(f1) && !feof(f2)) {
fread( &buf1, 1, sizeof(buf1), f1 );
fread( &buf2, 1, sizeof(buf2), f2 );
if (buf1 != buf2) {
fclose(f1);
fclose(f2);
return 0;
}
}
if (feof(f1) != feof(f2)) {
fclose(f1);
fclose(f2);
return 0;
}
fclose(f1);
fclose(f2);
return 1;
}