-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbbs.cpp
76 lines (67 loc) · 1.21 KB
/
bbs.cpp
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
#include "bbs.h"
// default constructor
BBS::BBS()
{
// default insecure params
this->p = 11;
this->q = 19;
// seed
this->x0 = 4;
// product of P & Q
this->n = p * q;
}
/*
set object parameters
@param blum prime number p
@param blum prime number q
@param integer seed
*/
void BBS::setParams(unsigned long long p, unsigned long long q, unsigned long long seed)
{
// choose p and q such that gcd(p, q) = 1
this->p = p;
this->q = q;
// random seed should be netween 1 & n-1
this->x0 = seed;
// blum integer
this->n = p * q;
}
/*
overloaded constructor
@param blum prime number p
@param blum prime number q
@param integer seed
*/
BBS::BBS(unsigned long long p, unsigned long long q, unsigned long long seed)
{
this->setParams(p, q, seed);
}
/*
Get next random number
*/
unsigned long long BBS::getRandNum()
{
unsigned long long nextRandNum = (this->x0 * this->x0) % this->n;
this->x0 = nextRandNum;
return nextRandNum;
}
/*
Get next random bit
*/
unsigned long long BBS::getRandBit()
{
return this->getRandNum() % 2;
}
void BBS::setP(unsigned long long p)
{
this->p = p;
}
void BBS::setQ(unsigned long long q)
{
this->q = q;
}
void BBS::setSeed(unsigned long long seed)
{
this->x0 = seed;
}
BBS::~BBS() {}