ECF 1.5
attack.cpp
1/*
2attack.cpp
3Written by Walter O. Krawec, Michael Nelson, and Eric Geiss
4Copyright (c) 2017
5
6Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
7
8The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9
10THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
11*/
12
13
14#include "attack.h"
15
16namespace QKD
17{
18
19 double Stats::BB84Rate()
20 {
21 double R01 = p0a - .5;
22 double R23 = p1a - .5;
23 double R02 = pa0 - .5*(1-p01+p10);
24 double R13 = -R02;
25
26 double I01 = p0b - .5;
27 double I23 = p1b - .5;
28 double I02 = .5*(1-p01+p10) - pb0;
29 double I13 = -I02;
30
31 double R03 = 1 - Qx - Qy - .5*(R01+R23+I01+I23);
32 double R12 = Qy - Qx + .5*(I01+I23-R01-R23);
33
34 double l01 = .5 + sqrt( (p10-p01)*(p10-p01) + 4*R03*R03 ) / (2.0*(2-p01-p10));
35 double l23 = .5 + sqrt( (p01-p10)*(p01-p10) + 4*R12*R12 ) / (2.0*(p01+p10));
36
37 double first = entropy( (1-p01) / (2.0-p01-p10) ) - entropy(l01);
38 double second = entropy( p01 / (p01+p10) ) - entropy(l23);
39
40 if(p01+p10 <= .0000001)
41 second = 0;
42 if(2.0-p01-p10 <= 0.0000001)
43 first = 0;
44
45 double SAE = (2-p01-p10)/2.0 * first + (p01+p10)/2.0 * second;
46
47 double key00 = .5*(1-p01);
48 double key11 = .5*(1-p10);
49 double key01 = .5*p01;
50 double key10 = .5*p10;
51
52 double H = HAB(key00,key01,key10,key11);
53
54 return SAE - H;
55 }
56
57 void Stats::symmetric(double Q)
58 {
59 p00 = 1-Q;
60 p01 = Q;
61 p10 = Q;
62 p11 = 1-Q;
63
64 Qx = Q;
65 Qy = Q;
66
67 p0a = .5;
68 p1a = .5;
69 pa0 = .5;
70
71 p0b = .5;
72 p1b = .5;
73 pb0 = .5;
74 }
75
76}