group.cpp
Go to the documentation of this file.
1 
12 #include "group.hpp"
13 
14 
15 using namespace arithm;
16 
17 
18 Group::Group(mpz_class order, mpz_class gen)
19 {
20  multOrder = order;
21  generator = gen;
22 }
23 
24 
26 {
27  return NULL;
28 }
29 
30 
31 // ------------------------------------------ element operations
32 
33 
35 {
36  return Elmt(0,this);
37 }
38 
39 
41 {
42  return Elmt(0,this);
43 }
44 
45 
47 {
48  return Elmt(0,this);
49 }
50 
51 
52 bool Group::compare(Elmt e1, Elmt e2)
53 {
54  return (e1.getValue() == e2.getValue());
55 }
56 
57 
58 // ------------------------------------------- array operations
59 
60 
62 {
63  if (e1.size() != e2.size())
64  {
65  std::cout<<"ERROR: in Group.multiplication(e1,e2), "
66  <<"arrays are not of the same size."
67  <<"\ne1.size()="<<e1.size()
68  <<"\ne2.size()="<<e2.size()<<std::endl;
69  exit(1);
70  }
71  ArrayOfElmts result;
72  for (unsigned int i=0; i<e1.size(); i++)
73  result.addElmt(
74  multiplication(e1.getElmt(i), e2.getElmt(i)));
75  return result;
76 }
77 
78 
80 {
81  ArrayOfElmts result;
82  for (unsigned int i=0; i<e.size(); i++)
83  result.addElmt(multInverse(e.getElmt(i)));
84  return result;
85 }
86 
87 
89 {
90  if (e.size() != s.size())
91  {
92  std::cout<<"ERROR: in Group.exponentiation(e,s), "
93  <<"arrays are not of the same size."
94  <<"\ne.size()="<<e.size()
95  <<"\ns.size()="<<s.size()<<std::endl;
96  exit(1);
97  }
98  ArrayOfElmts result;
99  for (unsigned int i=0; i<e.size(); i++)
100  result.addElmt(
101  exponentiation(e.getElmt(i), s.getElmt(i)));
102  return result;
103 }
104 
105 
106 
108 {
109  Elmt result = getOne();
110  for (unsigned int i=0; i<e.size(); i++)
111  result = multiplication(result,e.getElmt(i));
112  return result;
113 }
114 
115 
117 {
118 
119  if (e.size() != s.size())
120  {
121  std::cout<<"ERROR: in Group.expProduct(e,s), "
122  <<"arrays are not of the same size."
123  <<"\ne.size()="<<e.size()
124  <<"\ns.size()="<<s.size()<<std::endl;
125  exit(1);
126  }
127  Elmt result = getOne();
128  for (unsigned int i=0; i<e.size(); i++)
129  result = multiplication(
130  result,
131  exponentiation(e.getElmt(i),s.getElmt(i)));
132  return result;
133 }
134 
135 
136 
138 {
139  for (unsigned int i=0; i<e1.size(); i++)
140  if (! compare(e1.getElmt(i),e2.getElmt(i)) )
141  return false;
142  return true;
143 }
144 
145 
146 // ------------------------------------------- encoding/decoding
147 
148 
149 Elmt Group::encode(std::vector<uint8_t> message)
150 {
151  return Elmt(0,this);
152 }
153 
154 
155 std::vector<uint8_t> Group::decode(Elmt e)
156 {
157  std::vector<uint8_t> dummyResult;
158  return dummyResult;
159 }
160 
161 
162 // ------------------------------------------- obtaining elements
163 
164 
166 {
167  return getElmt(1);
168 }
169 
170 
172 {
173  ArrayOfElmts result;
174  for (unsigned int i=0; i<n; i++)
175  result.addElmt(getOne());
176  return result;
177 }
178 
179 
180 Elmt Group::getElmt(mpz_class repr)
181 {
182  return Elmt(repr,this);
183 }
184 
185 
187 {
188  if (!bt->isLeaf())
189  {
190  std::cout<<"ERROR: in Group.getElmt(bt), bt is not a "
191  <<"Leaf.\nbt=";
192  bt->prettyPrint("");
193  std::cout<<std::endl;
194  exit(1);
195  }
196  return Elmt(bt->toInteger(),this);
197 }
198 
199 
201 {
202  ArrayOfElmts result;
203  if (!bt->isNode())
204  {
205  std::cout<<"ERROR: in Group.getArray(bt), bt is not a "
206  <<"Node.\nbt=";
207  bt->prettyPrint("");
208  std::cout<<std::endl;
209  exit(1);
210  }
211  for (unsigned int i=0; i<bt->size(); i++)
212  result.addElmt(getElmt(bt->getChild(i)));
213  return result;
214 }
215 
216 
218  unsigned int nr,
219  unsigned int n0)
220 {
221  return ArrayOfElmts();
222 }
223 
224 
225 
226 // ------------------------------- data about the group
227 
228 
230 {
231  return multOrder;
232 }
233 
234 
235 unsigned int Group::getLeafSize()
236 {
237  return mpz_sizeinbase(multOrder.get_mpz_t(),2);
238 }
239 
240 
242 {
243  return getElmt(generator);
244 }
245 
246 
248 {
249  ArrayOfElmts result;
250  for (unsigned int i=0; i<n; i++)
251  result.addElmt(getGenerator());
252  return result;
253 }
254 
255 
256 bool Group::isIn(mpz_class repr)
257 {
258  return true;
259 }
260 
261 
262 std::string Group::getType()
263 {
264  return "Group";
265 }