This repository has been archived by the owner on Dec 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBuddy.cxx
39 lines (33 loc) · 1.49 KB
/
Buddy.cxx
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
//
// Created by Filippo Valle on 15/11/2018.
//
#include "Buddy.h"
bool Buddy::EveIsPresent = false;
void Buddy::InterceptQbit(Qbit *qbit) {
if (EveIsPresent) {
if (Qbit::DEBUG) {
printf("\nIntercepting qbit..\n");
std::cout << "received qbit: " << *qbit << std::endl;
}
ReceiveQbit(qbit);
qbit->PrepareState(qbit->GetBase(), qbit->GetState());
}
}
void Buddy::ReceiveQbit(Qbit *qbit){
if(Qbit::DEBUG) {
printf("\n\n**********\nReceiving qbit..\n");
std::cout << "received qbit: " << *qbit << std::endl; // stampo lo stato del qbit ricevuto
}
base measuringBase = (gRandom->Rndm()<0.5?ZeroOne:PlusMinus); // estraggo a caso una base
qbit->MeasureState(measuringBase); // misuro lo stato del qbit, proiettandolo con la base scelta
if(Qbit::DEBUG) std::cout << "measured qbit: " << *qbit << std::endl; // stampo lo stato del qbit trasformato
}
void Buddy::PrepareQbit(Qbit *qbit) {
if(Qbit::DEBUG) {
printf("\n\n**********\nPreparing qbit..\n");
std::cout << "received qbit: " << *qbit << std::endl;
}
base preparingBase = (gRandom->Rndm()<0.5?ZeroOne:PlusMinus); // estraggo la base da usare
polarization preparingPol = (gRandom->Rndm()<0.5); // estraggo lo stato
qbit->PrepareState(preparingBase, preparingPol); // preparo lo stato
}