ciphergroup.cpp
Go to the documentation of this file.
1 
12 #include "ciphertext.hpp"
13 #include "ciphergroup.hpp"
14 #include "arrayofciphers.hpp"
15 
16 using namespace elGamal;
17 
18 
19 
21 {
22  grp = group;
23 }
24 
25 
27 {
28  return grp;
29 }
30 
31 
33 {
34  return CipherText(bt,*this);
35 }
36 
37 
40 {
41  return ArrayOfCiphers(bt,*this);
42 }
43 
44 
45 // -------------------------------------------- Encryption/Decryption
46 
47 
48 
50  arithm::Elmt s)
51 {
54  return CipherText(u,v);
55 }
56 
57 
59 {
60  return grp->multiplication(
62  uv.getV());
63 }
64 
65 
67 {
68  return grp->exponentiation(uv.getU(),xl);
69 }
70 
71 
73 {
74  arithm::ArrayOfElmts result;
75  for (unsigned int i=0; i<uv.size(); i++)
76  result.addElmt(pdec(xl, uv.getCipherText(i)));
77  return result;
78 }
79 
80 
82 {
83  return grp->multiplication(uv.getV(),grp->multInverse(f));
84 }
85 
86 
88 {
89  arithm::ArrayOfElmts result;
90  for (unsigned int i=0; i<uv.size(); i++)
91  result.addElmt(tdec(uv.getCipherText(i),f.getElmt(i)));
92  return result;
93 }
94 
95 
96 // ------------------------------------------------ Group operations
97 
98 
99 
101 {
102  return CipherText(grp->exponentiation(c.getU(),s),
103  grp->exponentiation(c.getV(),s));
104 
105 }
106 
107 
109 {
110  return CipherText(grp->multiplication(c1.getU(),c2.getU()),
111  grp->multiplication(c1.getV(),c2.getV()));
112 }
113 
114 
117 {
119  grp->exponentiation(c.getVarray(),s));
120 }
121 
122 
125 {
126  return CipherText(grp->expProduct(c.getUarray(),s),
127  grp->expProduct(c.getVarray(),s));
128 }
129 
130 
132 {
133  return ( (grp->compare(c1.getU(), c2.getU())) &&
134  (grp->compare(c1.getV(), c2.getV())) );
135 }
136 
137 
139 {
140  for (unsigned int i=0; i<c1.size(); i++)
141  if (! compare(c1.getCipherText(i), c2.getCipherText(i)) )
142  return false;
143  return true;
144 }