-
Notifications
You must be signed in to change notification settings - Fork 0
/
Value.h
109 lines (65 loc) · 2.13 KB
/
Value.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
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
#pragma once
#include <iostream>
#include <vector>
using namespace std;
class Value;
class GF2m {
private:
vector<vector<int>> polynomials = {
{1, 1, 1}, // 2
{1, 0, 1, 1}, // 3
{1, 0, 0, 1, 1}, // 4
{1, 0, 0, 1, 0, 1}, // 5
{1, 0, 0, 0, 0, 1, 1}, // 6
{1, 0, 0, 0, 1, 0, 0, 1}, // 7
{1, 0, 0, 0, 1, 1, 1, 0, 1}, // 8
{1, 0, 0, 0, 0, 1, 0, 0, 0, 1}, // 9
{1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1}, // 10
{1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1}, // 11
{1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1}, // 12
{1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1}, // 13
{1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1}, // 14
{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1}, // 15
{1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1} // 16
};
static GF2m *field;
GF2m() { }
int m;
public:
vector<Value> inverse;
static GF2m *get_field() {
if(!field)
field = new GF2m();
return field;
}
void set_m(int dim);
int get_m();
int get_capacity();
vector<int> get_p();
};
class Value {
private:
vector<int> binary_mul(vector<int> factor_1, vector<int> factor_2) const;
vector<int> binary_div_reminder(vector<int> dividend, vector<int> divider) const;
protected:
int value;
vector<int> polynomial = GF2m::get_field()->get_p();
public:
Value();
Value(int v);
Value(const Value& v);
int get_value() const;
Value get_inverse() const;
static vector<int> from_10_to_2(int value);
static int from_2_to_10(vector<int> binary);
static Value pow(Value v, int p);
Value operator+(const Value &rv);
Value operator-(const Value &rv) const;
Value operator*(const Value &rv) const ;
Value operator/(Value &rv);
bool operator==(const Value &rv);
bool operator!=(const Value &rv);
friend Value operator/(const Value& lvalue, const Value& rvalue);
friend std::ostream& operator<<(std::ostream& os, const Value& value);
Value& operator=(const Value& rvalue);
};