-
Notifications
You must be signed in to change notification settings - Fork 10
/
key_gen.c
49 lines (45 loc) · 1.03 KB
/
key_gen.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
#include "qc_mdpc.h"
#include "matrix.h"
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char const *argv[])
{
int n0, p, w, t;
printf("Enter n0: ");
scanf("%d", &n0);
printf("Enter p: ");
scanf("%d", &p);
printf("Enter w: ");
scanf("%d", &w);
printf("Enter t: ");
scanf("%d", &t);
mdpc code = qc_mdpc_init(n0, p, w, t);
bin_matrix H = parity_check_matrix(code);
//printf("H Generated...\n");
bin_matrix G = generator_matrix(code);
//printf("G Generated...\n");
FILE *fp1, *fp2;
fp1 = fopen("Private_Key.txt", "a");
fprintf(fp1, "Private Key: Parity Check Matrix: \n");
for(int i = 0; i < H->rows; i++)
{
for(int j = 0; j < H->cols; j++)
{
fprintf(fp1, "%hu ", get_matrix_element(H, i, j));
}
fprintf(fp1, "\n \n");
}
fclose(fp1);
fp2 = fopen("Public_Key.txt", "a");
fprintf(fp2, "Public Key: Generator Matrix: \n");
for(int i = 0; i < G->rows; i++)
{
for(int j = 0; j < G->cols; j++)
{
fprintf(fp2, "%hu ", get_matrix_element(G, i, j));
}
fprintf(fp2, "\n \n");
}
fclose(fp2);
return 0;
}