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
|
#include "lib.h"
void main()
{
/*FILE *fp;
int keysize;
char *file_content, *chipertext, *block1, *block2;
int file_size = 61;
int min_hamming_distance;
fp = fopen("6.txt", "r");
if (fp == NULL) {
printf("Error open file\n");
exit(1);
}
file_content = malloc(file_size);
// read data and decode it from base64
// result is not a hex strin or?
while (fscanf(fp, "%60c", file_content) != EOF) {
file_size += 61;
file_content = realloc(file_content, file_size);
}
ciphertext = malloc(file_size);
decode_base64(file_content, ciphertext);
block1 = malloc(41);
block2 = malloc(41);
// split ciphertext in blocks of size 2 to 40
for(keysize=2; keysize < 40; keysize++) {
strncpy(block1, ciphertext, keysize);
strncpy(block2, &ciphertext[keysize+1], keysize);
tmp = hamming_distance(block1, block2);
tmp = tmp / keysize;
if (tmp < min_hamming_distance)
min_hamming_distance = tmp;
}
printf("keysize: %i\n", min_hamming_distance);
// transpose the blocks
*/
}
|