// nearest Basis to stored Value
        public override void Evaluate(IClassicState state)
        {
            int count = ReferenceBasis.CountElements;

            double stateValue = state.Value;
            double[] distances = new double[count];

            // CALCULAR DISTANCIAS
            double basisElementValue;
            for (int i = 0; i < count; i++)
            {
                basisElementValue = ReferenceBasis.getState(i).Value;
                distances[i] = System.Math.Abs(stateValue - basisElementValue);
            }

            // ELEJIR LA POSICION DE LA MENOR
            double result = double.PositiveInfinity;
            int resultPos = -1;
            double value;
            for (int j = 0; j < count; j++)
            {
                value = distances[j];
                if (value < result)
                {
                    result = value;
                    resultPos = j;
                }
            }

            // DEVOLVER LA POSICION DEL LA MENOR DISTANCIA
            MeasuredElement = resultPos;
        }
        public override void Evaluate(IClassicState state)
        {
            IClassicStateDebugger debuggerData = state.Debugger;
            IClassicStateDebugger debuggerElement = ReferenceBasis.getState(ReferenceElement).Debugger;

            debuggerData.setValue(debuggerElement.getValue());
        }
        public override void Evaluate(IClassicState state)
        {
            IClassicStateDebugger debugger = state.Debugger;
            double random = RandomnessFactory.GetSingleIntenger();

            debugger.setValue(random);
        }
        public override void Evaluate(IClassicState state)
        {
            if (Configuration.DelayEnabled == false) { return; }

            if (Configuration.DelayTicks != 0)
            {
                System.Threading.Thread.Sleep(Configuration.DelayTicks);
            }
        }
 public ClassicStateDebugger(IClassicState state)
     : base()
 {
     if (state is ClassicStateAbstract)
     {
         _abstractState = (ClassicStateAbstract)state;
     }
     else
     {
         throw new ClassicStateException();
     };
 }
 public ClStateDebugger(IClassicState state)
     : base()
 {
     if (state is AbstractClassicState)
     {
         _abstractState = (AbstractClassicState)state;
     }
     else
     {
         throw new ExceptionClassicState();
     };
 }
        public AbstractClassicDatatype(int numLevels, int size, bool initialize)
            : base()
        {
            IClassicState[] states = new IClassicState[size];
            for (int index=0;index<size;index++)
            {
                states[index] = ClassicStateFactory.generateState(numLevels);
            }
            _internalCollection = ClassicStateFactory.generateStateCollection(states);

            if (initialize) { Initialize(); }
        }
        public override void Evaluate(IClassicState state)
        {
            if (Configuration.NoiseEnabled == false) { return; }

            if (RandomnessFactory.GetSingleNormalized() < Configuration.NoiseFactor)
            {
                IClassicStateDebugger debugger = state.Debugger;
                double value = debugger.getValue();
                double random = RandomnessFactory.GetSingleDoubleIntervalByCenter(value, value + (debugger.getNumLevels() * 2));
                debugger.setValue(random);
            }
        }
        public override void Evaluate(IClassicState state)
        {
            if (Configuration.DelayEnabled == false) { return; }

            if (Configuration.DelayTicks != 0)
            {
                long startWait = System.DateTime.UtcNow.Ticks;
                while (System.DateTime.UtcNow.Ticks - startWait < Configuration.DelayTicks)
                {
                    System.Windows.Forms.Application.DoEvents();
                }
            }
        }
        public override void Evaluate(IClassicState state)
        {
            if (Configuration.NoiseEnabled == false) { return; }

            if (Configuration.NoiseFactor != 0)
            {
                IClassicStateDebugger debugger = state.Debugger;
                double value = debugger.getValue();
                double size = RandomnessAlgorithmFactory.GetSingleNormalized() / Configuration.NoiseFactor;
                double random = RandomnessAlgorithmFactory.GetSingleDoubleIntervalByCenter(value, size / 2);
                debugger.setValue(random);
            }
        }
        private void CHEC_EavesdropperProcessCheckPositions(IProtocolAgent agent, IClassicState state)
        {
            int receivedPos = Eavesdropper.counterReceivedClassic - 1;
                BB84Log("CHEC: STEP 1: ", receivedPos, " | Eavesdropper State Received: ", state.generateClassicDebugger().ShortDebug);

                IClassicBit ClassicBit = ClassicDatatypeFactory.generateBit(false);
                ClassicBit.AssociateState(state);
                bool decode = ClassicDatatypeFactory.decodeBitByUsualBasis(ClassicBit);
                BB84Log("CHEC: STEP 1: ", receivedPos, " | Eavesdropper conversion into Bit: ", decode.ToString());

                // store and 'decodedBit'
                CHEC_eavesdropperComparisonSelected.Add(decode);
                if (decode) //seletected
                {
                    CHEC_eavesdropperComparisonIndexes.Add(receivedPos);
                }
        }
        private void GENE_SlaveProcessBasisData(IProtocolAgent agent, IClassicState state)
        {
            int receivedPos = AgentSlave.counterReceivedClassic - 1;
                BB84Log("BB84 GENE STEP 2", receivedPos,"Slave State Receive", state.Debugger.ShortDebug);

                IClassicBit ClassicBit = ClassicDatatypeFactory.generateBit(false);
                ClassicBit.AssociateState(state);
                bool decode = ClassicDatatypeFactory.decodeBitByUsualBasis(ClassicBit);
                BB84Log("BB84 GENE STEP 2", receivedPos,"Slave conversion into Bit", decode.ToString());

                // get element
                bool usedBasis = (bool)GENE_slaveUsedBasisCollection[receivedPos];
                //bool decodedBit = (bool)GENE_slaveDecodedBitCollection[receivedPos];

                bool coincidence = (usedBasis == decode);
                if (coincidence)
                { BB84Log("BB84 GENE STEP 2","Slave found coincidence in Basis at POS", receivedPos); }

                // store 'coincidence' pos
                GENE_slaveCoincidences.Add(coincidence);
        }
        private void GENE_MasterProcessCoincidencesData(IProtocolAgent agent, IClassicState state)
        {
            // no hace falta comparar con las bases usadas o datos usadas
                // en este caso solo se transmite si el la estación cliente detecto coincidencia

                int receivedPos = AgentMaster.counterReceivedClassic - 1;
                BB84Log("BB84 GENE STEP 3", receivedPos,"Master State Receive", state.Debugger.ShortDebug);

                IClassicBit ClassicBit = ClassicDatatypeFactory.generateBit(false);
                ClassicBit.AssociateState(state);
                bool decode = ClassicDatatypeFactory.decodeBitByUsualBasis(ClassicBit);
                BB84Log("BB84 GENE STEP 3", receivedPos,"Master conversion into Bit", decode.ToString());

                if (decode)
                { BB84Log("BB84 GENE STEP 3","Master found coincidence in Basis at POS", receivedPos); }

                GENE_masterCoincidences.Add(decode);
        }
        private void GENE_EavesdropperProcessCoincidencesData(IProtocolAgent agent, IClassicState state)
        {
            int receivedPos = AgentEavesdropper.counterReceivedClassic - 1;
                BB84Log("BB84 GENE STEP 3", receivedPos,"Eavesdropper State Receive", state.Debugger.ShortDebug);

                IClassicBit ClassicBit = ClassicDatatypeFactory.generateBit(false);
                ClassicBit.AssociateState(state);
                bool decode = ClassicDatatypeFactory.decodeBitByUsualBasis(ClassicBit);
                BB84Log("BB84 GENE STEP 3", receivedPos,"Eavesdropper conversion into Bit", decode.ToString());

                if (decode)
                { BB84Log("BB84 GENE STEP 3","Eavesdropper found in Basis coincidence at POS", receivedPos); }

                GENE_eavesdropperCoincidences.Add(decode);
        }
 public static IClassicState generateState(IClassicState state)
 {
     IClassicState result = generateState(state.Debugger.getNumLevels());
     result.Value = state.Value;
     return result;
 }
Example #16
0
 // EVENTS
 public void transmitClassic(IProtocolAgent agent, IClassicState state)
 {
     TesterLog("Classic TRANSMISSION " + agent.AgentName);
     TesterLog(state.generateClassicDebugger().FullDebug);
 }
 protected virtual void PropagateOnClassicReceive(IChannelStation station, IClassicState state)
 {
     _counterReceivedClassic++;
     if (OnClassicReceive != null)
     { OnClassicReceive(this, state); };
 }
        private void CHEC_EavesdropperProcessCheckValuesSlave(IProtocolAgent agent, IClassicState state)
        {
            int receivedPos = Eavesdropper.counterReceivedClassic - 1;
                BB84Log("CHEC: STEP 2: ", receivedPos, " | Eavesdropper State Receive: ", state.generateClassicDebugger().ShortDebug);

                IClassicBit ClassicBit = ClassicDatatypeFactory.generateBit(false);
                ClassicBit.AssociateState(state);
                bool decode = ClassicDatatypeFactory.decodeBitByUsualBasis(ClassicBit);
                BB84Log("CHEC: STEP 2: ", receivedPos, " | Eavesdropper conversion into Bit: ", decode.ToString());

                //// get index
                int index = (int)CHEC_masterComparisonIndexes[receivedPos];
                BB84Log("CHEC: STEP 2: ", receivedPos, " | Eavesdropper -Slave- stores for checking check POS ", index, " with VALUE ", decode);

                CHEC_eavesdropperSlaveComparisonValuesReceived.Add(decode);
        }
 public void AssociateState(IClassicState state)
 {
     InternalCollection.setObject(state, 0);
 }
Example #20
0
 // EVENTS
 public void transmitClassic(IProtocolAgent agent, IClassicState state)
 {
     TesterLog("Classic", "TRANSMISSION", agent.AgentName, state.Debugger.FullDebug);
 }
Example #21
0
 public void receiveClassic(IProtocolAgent agent, IClassicState state)
 {
     TesterLog("Classic", "RECEPTION", agent.AgentName, state.Debugger.FullDebug);
 }
 public ClassicStateBasic(IClassicState state)
     : this(state.generateClassicDebugger().getNumLevels(), state.Value)
 {
 }
 public void Send(IClassicState state)
 {
     Station.ClassicTransmitSynchronous(state);
 }
 protected override void PropagateOnClassicReceive(IChannelStation station, IClassicState state)
 {
     IClassicBit tempBit = ClassicDatatypeFactory.generateBit(false);
     tempBit.AssociateState(state);
     ReceivedData.Add(ClassicDatatypeFactory.decodeBitByUsualBasis(tempBit));
     base.PropagateOnClassicReceive(station,state);
 }
 protected virtual void PropagateOnClassicTransmit(IChannelStation station, IClassicState state)
 {
     _counterTransmitedClassic++;
     if (OnClassicTransmit != null)
     { OnClassicTransmit(this, state); };
 }
        private void CHEC_SlaveProcessCheckPositions(IProtocolAgent agent, IClassicState state)
        {
            int receivedPos = AgentSlave.counterReceivedClassic - 1;
                BB84Log("BB84 CHEC STEP 1", receivedPos,"Slave State Received", state.Debugger.ShortDebug);

                IClassicBit ClassicBit = ClassicDatatypeFactory.generateBit(false);
                ClassicBit.AssociateState(state);
                bool decode = ClassicDatatypeFactory.decodeBitByUsualBasis(ClassicBit);
                BB84Log("BB84 CHEC STEP 1", receivedPos,"Slave conversion into Bit", decode.ToString());

                // store and 'decodedBit'
                CHEC_slaveComparisonSelected.Add(decode);
                if (decode) //seletected
                {
                    CHEC_slaveComparisonIndexes.Add(receivedPos);
                }
        }
Example #27
0
 public void receiveClassic(IProtocolAgent agent, IClassicState state)
 {
     TesterLog("Classic RECEPTION " + agent.AgentName);
     TesterLog(state.generateClassicDebugger().FullDebug);
 }
        private void CHEC_SlaveProcessCheckValues(IProtocolAgent agent, IClassicState state)
        {
            int receivedPos = AgentSlave.counterReceivedClassic - 1;
                BB84Log("BB84 CHEC STEP 2", receivedPos,"Slave State Receive", state.Debugger.ShortDebug);

                IClassicBit ClassicBit = ClassicDatatypeFactory.generateBit(false);
                ClassicBit.AssociateState(state);
                bool decode = ClassicDatatypeFactory.decodeBitByUsualBasis(ClassicBit);
                BB84Log("BB84 CHEC STEP 2", receivedPos,"Slave conversion into Bit", decode.ToString());

                //// get index
                int index = (int)CHEC_slaveComparisonIndexes[receivedPos];
                BB84Log("BB84 CHEC STEP 2", receivedPos,"Slave stores for checking check POS", index,"with VALUE", decode);

                CHEC_slaveComparisonValuesReceived.Add(decode);
        }
        private void GENE_EavesdropperProcessBasisData(IProtocolAgent agent, IClassicState state)
        {
            //int receivedPos = Eavesdropper.counterReceivedClassic - 1;
                //BB84Log(receivedPos,"Eavesdropper State Receive", state.Debugger.ShortDebug);

                //IClassicBit ClassicBit = ClassicDataFactory.generateBit(false);
                //ClassicBit.AssociateState(state);
                //bool decode = ClassicDataFactory.decodeBitByBasis(ClassicBit, FactoryRandom.GetSingleBinary());
                //BB84Log(receivedPos,"Eavesdropper conversion into Bit", decode.ToString());

                //// get element
                //bool usedBasis = (bool)GENE_eavesdropperUsedBasisCollection[receivedPos];
                ////bool decodedBit = (bool)GENE_eavesdropperDecodedBitCollection[receivedPos];

                //bool coincidence = (usedBasis == decode);
                //if (coincidence)
                //{ BB84Log("             Eavesdropper found coincidence at POS", receivedPos); }

                //// store 'coincidence' pos
                //GENE_eavesdropperCoincidences.Add(coincidence);
        }
 protected override void PropagateOnClassicReceive(IChannelStation station, IClassicState state)
 {
     if (Automata.State.ID != ProtocolBurstAgentAbstract.StatusSending)
     {
         IClassicBit tempBit = ClassicDatatypeFactory.generateBit(false);
         tempBit.AssociateState(state);
         BufferReceive.Add(ClassicDatatypeFactory.decodeBitByUsualBasis(tempBit));
     }
     base.PropagateOnClassicReceive(station, state);
 }