-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.cpp
120 lines (95 loc) · 2.05 KB
/
main.cpp
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
#include <iostream>
#include <fstream>
#include <random>
#include <ctime>
#include "matrix.h"
#include "Source.h"
using namespace std;
const int m=1042,n=233,l=233,q=32749,r=37,t=2;
const double alpha=0.000217;
//amnltrq
ofstream key("key.txt");
ofstream ci("ciphertext.txt");
ofstream rep("report.txt");
void output(ostream& out,matrix m)
{
for(int i=0;i<m.n;i++)
{
for(int j=0;j<m.m;j++)
{
out<<m[i][j];
out<<" ";
}
if(m.m>1)
{
out<<"\n";
}
}
out<<"\n";
}
int cmp(matrix l,matrix r)
{
int cnt=0;
for(int i=0;i<l.n;i++)
{
if(l[i][0]!=r[i][0])
{
rep<<"pos: "<<i<<" l: "<<l[i][0]<<" r: "<<r[i][0]<<"\n";
cnt++;
}
}
//cout<<"\nwrong "<<cnt<<" in "<<l.n<<", "<<double((l.n-cnt)*100)/double(l.n)<<"% right\n";
rep<<"\nwrong "<<cnt<<" in "<<l.n<<", "<<double((l.n-cnt)*100)/double(l.n)<<"% right\n";
return cnt;
}
int main(void)
{
srand(time(NULL));
int cs,cnt=0;
crypto cpt(alpha,m,n,l,t,r,q);
cout<<"Please input the number of test cases: ";
cin>>cs;
pair<matrix,matrix> pub;
matrix pri;
pub=cpt.pub();
pri=cpt.pri();
rep<<"REPORT:\n";
rep<<"\nA:\n";
output(rep,pub.first);
rep<<"\nS:\n";
output(rep,pri);
rep<<"\nB:\n";
output(rep,pub.second);
rep<<"alpha: "<<alpha<<"\n";
rep<<"m: "<<m<<"\n";
rep<<"n: "<<n<<"\n";
rep<<"l: "<<l<<"\n";
rep<<"t: "<<t<<"\n";
rep<<"r: "<<r<<"\n";
rep<<"q: "<<q<<"\n";
rep<<"\n================\n";
for(int i=1;i<=cs;i++)
{
matrix plt(l,1,2,UNIFORM);
pair<matrix,matrix> ct=cpt.enc(plt);
matrix pt2=cpt.dec(ct);
rep<<"Case "<<i<<"\n\n";
key<<"Case "<<i<<"\n\n";
ci<<"Case "<<i<<"\n\n";
ci<<"u:\n";
output(ci,ct.first);
ci<<"c:\n";
output(ci,ct.second);
key<<"plt\n\n";
output(key,plt);
key<<"pt2\n";
output(key,pt2);
cnt+=cmp(plt,pt2);
rep<<"\n================\n";
key<<"\n================\n";
ci<<"\n================\n";
}
cout<<"\ntotal wrong "<<cnt<<" in "<<l*cs<<", "<<double((l*cs-cnt)*100)/double(l*cs)<<"% right\n";
rep<<"\ntotal wrong "<<cnt<<" in "<<l*cs<<", "<<double((l*cs-cnt)*100)/double(l*cs)<<"% right\n";
return 0;
}