-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
64 lines (53 loc) · 1.94 KB
/
main.c
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
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <time.h>
#include "utils.h"
#include "des.h"
#define ITER 1000000
void test_encrypt_distrb(void) {
uint64_t encrypt[ITER] = {0};
uint64_t plain = 0, key = 0;
uint64_t subKey[16] = {0};
srand((unsigned int)time(NULL));
for (int i = 0; i < ITER; i++) {
plain = rand64() % ((uint64_t)CONST_P * (uint64_t)CONST_P);
key = rand64() % ((uint64_t)CONST_P * (uint64_t)CONST_P);
generate_subkeys(&key, subKey);
encrypt[i] = modpDES_encrypt_decypt(plain, ENCRYPT, subKey);
}
FILE *fp = fopen("data_modpDES.csv", "w");
for (int i = 0; i < ITER; i++) {
fprintf(fp, "%lu,", encrypt[i]);
}
fclose(fp);
return;
}
int main(void) {
// plain_text encrypt_text decrypt_text key均应该小于p的平方
uint64_t plain_text = 0, encrypt_text = 0, decrypt_text = 0, k = 0;
uint64_t subKey[16] = {0};
int start, end;
int test_speed_iter = 10000000;
srand((unsigned int)time(NULL));
k = rand64() % ((uint64_t)CONST_P * (uint64_t)CONST_P);
generate_subkeys(&k, subKey);
plain_text = rand64() % ((uint64_t)CONST_P * (uint64_t)CONST_P);
encrypt_text = modpDES_encrypt_decypt(plain_text, ENCRYPT, subKey);
decrypt_text = modpDES_encrypt_decypt(encrypt_text, DECRYPT, subKey);
// start = clock();
// for (int i = 0; i < test_speed_iter; i++) {
// encrypt_text = DES_encrypt_decypt(plain_text, ENCRYPT, subKey);
// }
// end = clock();
// printf("ENCRYPT: %fs for %d times\n", (double)(end - start) / CLOCKS_PER_SEC, test_speed_iter);
// start = clock();
// for (int i = 0; i < test_speed_iter; i++) {
// decrypt_text = DES_encrypt_decypt(encrypt_text, DECRYPT, subKey);
// }
// end = clock();
// printf("DECRYPT: %fs for %d times\n", (double)(end - start) / CLOCKS_PER_SEC, test_speed_iter);
// test_encrypt_distrb();
return 0;
}