Ejemplo n.º 1
0
 // Reads a photon with the chosen filter.
 public char readPhoton(AlicePhoton electroMagneticRadiationPacket, bool filter, ref int CurrentBit)
 {
     // true = x; false = +
     if (electroMagneticRadiationPacket.Rectilinear == filter)
     {
         if (electroMagneticRadiationPacket.Rectilinear == true && electroMagneticRadiationPacket.Polarization == true)
         {
             CurrentBit = 1;
             return('/');    // rectilinear is x and polar is true so 1
         }
         else if (electroMagneticRadiationPacket.Rectilinear == true && electroMagneticRadiationPacket.Polarization == false)
         {
             CurrentBit = 0;
             return('\\');    // rectilinear is x and polar is false so 0
         }
         else if (electroMagneticRadiationPacket.Rectilinear == false && electroMagneticRadiationPacket.Polarization == true)
         {
             CurrentBit = 1;
             return('|'); // rectilinear is + and polar is true so 1
         }
         else             //if(electroMagneticRadiationPacket.Rectilinear == false && electroMagneticRadiationPacket.Polarization == false)
         {
             CurrentBit = 0;
             return('-');    // rectilinear is + and polar is false so 0
         }
     }
     else
     {
         Random r      = new Random();
         int    result = r.Next(0, 2);
         if (electroMagneticRadiationPacket.Rectilinear == false)// && electroMagneticRadiationPacket.Polarization == true)
         {
             if (result == 0)
             {
                 CurrentBit = 0;
                 return('\\'); // read random wrong answer
             }
             else
             {
                 CurrentBit = 1;
                 return('/'); // read random wrong answer
             }
         }
         else //if (electroMagneticRadiationPacket.Rectilinear == true) && electroMagneticRadiationPacket.Polarization == false)
         {
             if (result == 0)
             {
                 CurrentBit = 0;
                 return('-'); // read random wrong answer
             }
             else
             {
                 CurrentBit = 1;
                 return('|'); // read random wrong answer
             }
         }
     }
 }
Ejemplo n.º 2
0
        private void fillAlicePhotons()
        {
            Random r = new Random();

            for (int i = 0; i < photonsOfAlice.Length; i++)
            {
                photonsOfAlice[i] = new AlicePhoton(r.Next(0, 4));
                //alicePhotons[i] = r.Next(0, 4);
            }
        }