-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.cpp
141 lines (121 loc) · 3.36 KB
/
Main.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
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#include <iostream>
using namespace std;
#include "Party.h"
#include "Channel.h"
#include "Block.h"
#include <fstream>
#include "Pi.h"
#include "PiOne.h"
#include "PiRand.h"
#include "PiZero.h"
#include <math.h>
int runProtocol(Party & Alice, Party & Bob, int limit, Channel& channelAliceToBob, Channel& channelBobToAlice)
{
int round = 0;
while (round != 7000000000) // round = 2k bits (k bits each party), run protocol "on the fly"
{
// protocol finished
if (Alice.getCount()*BLOCK_SIZE - Alice.getCountOnes() >= limit && Bob.getCount()*BLOCK_SIZE - Bob.getCountOnes() >= limit)
break;
//calculate parity for each party - line 3
Alice.setParity(Alice.getTindex() % 4);
Bob.setParity(Bob.getTindex() % 4);
//calculate new for each party - line 4
Alice.setNewIndex((Alice.getTindex() + Alice.getTempS()[(Alice.getParity() + 1) % 4].isFull() + 1) % 4);
Bob.setNewIndex((Bob.getTindex() + Bob.getTempS()[(Bob.getParity() + 1) % 4].isFull() + 1) % 4);
if (Alice.getSendZero() == false && Bob.getSendZero() == false) // no errors
{
Party::noErrorsOnBothSides(Alice, Bob, channelAliceToBob, channelBobToAlice); // send block of k bits, each
// lines 11-19 - check all scenarios
Party::checkAllCasesInProtocol(Alice);
Party::checkAllCasesInProtocol(Bob);
}
else if (Alice.getSendZero() == true && Bob.getSendZero() == true) // both parties saw error last round
{
Party::bothSidesSeeErrors(Alice, Bob, channelAliceToBob, channelBobToAlice);
}
else if (Alice.getSendZero() == true && Bob.getSendZero() == false) // Alice saw error last round
{
Party::AliceSeesErrorBobNot(Alice, Bob, channelAliceToBob, channelBobToAlice);
Party::checkAllCasesInProtocol(Bob);
}
else if (Alice.getSendZero() == false && Bob.getSendZero() == true) // Bob saw error last round
{
Party::BobSeesErrorAliceNot(Alice, Bob, channelAliceToBob, channelBobToAlice);
Party::checkAllCasesInProtocol(Alice);
}
round++;
}
return round;
}
int mainExe(Party &Alice,Party &Bob)
{
Channel channelAliceToBob(100000);
Channel channelBobToAlice(100000);
Party::getRandom(Alice, Bob);
int round1 = runProtocol(Alice, Bob, 32, channelAliceToBob, channelBobToAlice);
Alice.setRandBob(Alice.getTR()[0]);
Bob.setRandAlice(Bob.getTR()[0]);
Alice.pumpRandom();
Bob.pumpRandom();
Alice.nextPhase();
Bob.nextPhase();
int round2 = runProtocol(Alice, Bob, n, channelAliceToBob, channelBobToAlice);
return (round1 + round2)*BLOCK_SIZE;
}
void main()
{
std::srand(std::time(0));
int test = 2;
if (test == 1)
{
double count[10000];
for (int i = 0; i <= 10000; i++)
{
count[i] = 0;
}
for (int j = 4; j <= 1000; j++)
{
BLOCK_SIZE = j;
for (int i = 0; i < 2; i++)
{
//PiAlice::generateTrans();
//PiBob::generateTrans();
// count[j] += mainExe(Alice,Bob);
}
}
for (int i = 0; i < 2; i++)
{
char d = (char)(7);
printf("%c\n", d);
}
ofstream myfile;
myfile.open("pi1_4-1000.txt");
for (int j = 4; j <= 1000; j++)
{
count[j] = count[j] / 2;
myfile << count[j] << endl;
}
myfile.close();
}
else if (test == 0)
{
// PiAlice::generateTrans();
// PiBob::generateTrans();
//mainExe(Alice,Bob);
}
else if (test == 2)
{
int rate = 0;
BLOCK_SIZE = 16;
for (int i = 0; i < 10; i++)
{
Party Alice(2);
Party Bob(2);
rate += mainExe(Alice,Bob);
}
std::cout << ((rate / 10));
}
int y;
cin >> y;
}