-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpaillierpublickey.cpp
More file actions
45 lines (36 loc) · 1.01 KB
/
paillierpublickey.cpp
File metadata and controls
45 lines (36 loc) · 1.01 KB
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
#include <QDebug>
#include "modularmath.hpp"
#include "paillierpublickey.hpp"
#include "bigintmath.hpp"
PaillierPublicKey::PaillierPublicKey(QCA::BigInteger num, QCA::BigInteger gen)
{
n = num;
g = gen;
n2 = n*n;
}
QCA::BigInteger PaillierPublicKey::getRandomNumber()
{
//Number chosen based on atmospheric turbulence.
//Guaranteed to be random.
QCA::BigInteger random = "2392739600";
return random;
}
QCA::BigInteger PaillierPublicKey::encrypt(QCA::BigInteger msg)
{
QCA::BigInteger random = getRandomNumber();
QCA::BigInteger step1 = ModularMath::modexp(g,msg,n2);
QCA::BigInteger step2 = ModularMath::modexp(random,n,n2);
return (step1 * step2) % n2;
}
QCA::BigInteger PaillierPublicKey::add(const QCA::BigInteger &a, const QCA::BigInteger &b)
{
return a * b % n2;
}
QCA::BigInteger PaillierPublicKey::increment(const QCA::BigInteger &n)
{
return add(n, encrypt(1));
}
QCA::BigInteger PaillierPublicKey::mutate(const QCA::BigInteger &n)
{
return add(n, encrypt(0));
}