Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
B92Finite/3statebb84_finite.cpp
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
147 lines (118 sloc)
4.21 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "key_rate_utils.hpp"; | |
namespace bb84_3_state{ | |
using namespace key_rate_utils; | |
using namespace std; | |
double STEP = 1e-3; | |
inline double calculate_blam1(double blam2, bool mismatched = true){ | |
//Calculate | |
return 1 - blam2 - 2*AtoB["PPM"] + calculate_q(mistmatched); | |
} | |
ke | |
double calculate_q(bool mistmatched = true){ | |
//no mismatched would be different | |
if (mismatched) | |
return AtoB["P0P"] + AtoB["P1P"] - 1; | |
else | |
return sqrt(AtoB["P00"]*AtoB["P01"]) + sqrt(AtoB["P10"]*AtoB["P11"]); | |
} | |
//Need to change generate noise statistics tp add X stats for bob! | |
//in finite case iteratate throuugh noise stats and change them based on uncertainty" | |
double calculate_key_rate_asymptotic(double noise, bool symmetric, double CAD=1, bool mismatched = true){ | |
generateNoiseStatistics(symmetric, noise); | |
//add CAD | |
vector<double> E0 = [AtoB["P00"], AtoB["P01"]]; | |
vector<double> E1 = [AtoB["P10"], AtoB["P11"]]; | |
double lim2 = sqrt(AtoB["P10"]*AtoB["P01"]]); | |
double min_ent = 1; | |
for (double big_lam2 = -lim2; big_lam2 <= lim2 ; lim2+=STEP){ | |
vector<double> Ls = [calculate_blam1(big_lam2, mismatched), big_lam2]; | |
double s_ent = s_entropy(E0, E1, Ls, CAD); | |
if (s_ent > -.5 && s_ent < min_ent) | |
min_ent = s_ent; | |
} | |
vector<double> Pij = [AtoB["P00"], AtoB["P01"], AtoB["P10"], AtoB["P11"]]; | |
vector<double> Pij_key; | |
transform(Pij.begin(), Pij.end(), back_inserter(Pij_key), | |
[CAD](double p) -> double {return pow(p, CAD);} ); | |
double key_rate = min_ent - H_AB(Pij_key); | |
return key_rate; | |
} | |
double calculate_key_rate_finite_outside(double noise, bool symmetric, double N, double Pza, double Pzx, double Pstats, double CAD = 1, bool mistmatched =1){ | |
generateNoiseStatistics(symmetric, noise); | |
int Tzz, Mzz, Mzx, Mxx, Nzz; | |
Tzz = Pza*Pzb*N; | |
Mzz = Pstats * Tzz; | |
Nzz = (1-Pstats)*Tzz; | |
Mzx = N * (1-Pzb)*Pzz; | |
Mxx = N * (1-Pzb)*(1-Pza); | |
double epsilon_prime = .001; | |
int d = 2; | |
double Xizz, Xizx, Xixx; | |
auto gamma = [epsilon_prime,d] (int m) {return sqrt((2*ln(1/epsilon_prime) + d*ln(m+1))/m);}; | |
auto B00, B01, B10, B11, B0P, B1P, BPM; | |
auto M00, M01, M10, M11, M0P, M1P, MPM; | |
auto min_key_rate = 1; | |
auto ent = 0; | |
B00 = AtoB["P00"]; | |
B01 = AtoB["P01"]; | |
B10 = AtoB["P10"]; | |
B11 = AtoB["P11"]; | |
B0P = AtoB["P0P"]; | |
B1P = AtoB["P1P"]; | |
//AtoB["P0M"]-=Gzx; | |
//AtoB["P1M"]-=Gzx1; | |
BPM - AtoB["PPM"]; | |
for (auto Gzz = -gamma(Mzz); Gzz <= gamma(Mzz); Gzz +=STEP){ | |
for (auto Gzx = -gamma(Mzx); Gzx <= gamma(Mzx); Gzx +=STEP){ | |
for (auto Gzz1 = -gamma(Mzz); Gzz1 <= gamma(Mzz); Gzz1 +=STEP){ | |
for (auto Gzx1 = -gamma(Mzx); Gzx1 <= gamma(Mzx); Gzx1 +=STEP){ | |
for (auto Gxx = -gamma(Mxx); Gzx <= gamma(Mxx); Gxx +=STEP){ | |
AtoB["P00"] = B00 + Gzz; | |
AtoB["P01"] = B01 - Gzz; | |
AtoB["P10"] = B10 + Gzz1; | |
AtoB["P11"] = B11 - Gzz1; | |
AtoB["P0P"] = B0P + Gzx; | |
AtoB["P1P"] = B1P + Gzx1; | |
//AtoB["P0M"]-=Gzx; | |
//AtoB["P1M"]-=Gzx1; | |
AtoB["PPM"] = BPM + Gxx | |
ent = calculate_key_rate_finite_inside(CAD, mismatched); | |
if (ent < min_key_rate){ | |
min_key_rate = ent; | |
M00 = AtoB["P00"]; | |
M01 = AtoB["P01"]; | |
M10 = AtoB["P10"]; | |
M11 = AtoB["P11"]; | |
M0P = AtoB["P0P"]; | |
M1P = AtoB["P1P"]; | |
MPM - AtoB["PPM"]; | |
} | |
} | |
} | |
} | |
} | |
} | |
return Nzz * min_key_rate / N; //(This is the number of secret key bits/number of measurements) | |
} | |
double calculate_key_rate_finite_inside(int CAD = 1, bool mistmatched = true){ | |
//add CAD | |
vector<double> E0 = [AtoB["P00"], AtoB["P01"]]; | |
vector<double> E1 = [AtoB["P10"], AtoB["P11"]]; | |
double lim2 = sqrt(AtoB["P10"]*AtoB["P01"]]); | |
double min_ent = 1; | |
for (double big_lam2 = -lim2; big_lam2 <= lim2 ; lim2+=STEP){ | |
vector<double> Ls = [calculate_blam1(big_lam2. mistmatched), big_lam2]; | |
double s_ent = s_entropy(E0, E1, Ls, CAD); | |
if (s_ent > -.5 && s_ent < min_ent) | |
min_ent = s_ent; | |
} | |
vector<double> Pij = [AtoB["P00"], AtoB["P01"], AtoB["P10"], AtoB["P11"]]; | |
vector<double> Pij_key; | |
transform(Pij.begin(), Pij.end(), back_inserter(Pij_key), | |
[CAD](double p) -> double {return pow(p, CAD);} ); | |
double key_rate = min_ent - H_AB(Pij_key); | |
return key_rate; | |
} | |
int main(int argc, char** argv){ | |
} | |
} |