-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSource.h
55 lines (48 loc) · 1.08 KB
/
Source.h
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
#include<iostream>
#include<random>
#include<vector>
#include<math.h>
#include"matrix.h"
using namespace std;
class crypto
{
public:
crypto(double a, int m, int n, int l, int t, int r, int q);
pair<matrix, matrix> enc(matrix v);
matrix dec(pair<matrix, matrix>uc);
pair<matrix, matrix> pub(void);
matrix pri(void);
private:
matrix A, E, B, S;
double a;
int m, n, l, t, r, q;
};
crypto::crypto(double a_, int m_, int n_, int l_, int t_, int r_, int q_)
:A(m_, n_, q_, UNIFORM), S(n_, l_, q_, UNIFORM), E(m_, l_, q_, GAUSS, (double)a_*q_ / (M_2_SQRTPI * M_SQRT2)),
a(a_), m(m_), n(n_), l(l_), t(t_), r(r_), q(q_)
{
B = A * S + E;
}
pair<matrix, matrix> crypto::enc(matrix v)
{
matrix R(m, 1, r-1, UNIFORM);//cout<<"asdf";
/*for (int i = 0; i < m; i++)
{
R[i][0] -= r;
}*/
matrix u = (~A)*R, c = (~B)*R;
c=c+f(v,q);
return pair<matrix, matrix>(u, c);
}
matrix crypto::dec(pair<matrix, matrix> uc)
{//cout<<t;
return f_rev((uc.second - (~S) * uc.first),q);
}
pair<matrix, matrix> crypto::pub(void)
{
return pair<matrix, matrix>(A, B);
}
matrix crypto::pri(void)
{
return S;
}