% Quantum Key Distribution (QKD) protocol
% Version: January 14, 2016
classdef encoder < QKD_Peer
    % QKP encoder   
    methods
        % encoding function
        function [ S,selectedbases ] = encode(obj, n)
            % Generate and array of n random data bits
            obj.data=randi([0 1],1,n);
            % sent photons
            S=[];
            % save basis of each photon
            selectedbases=[];
            for i=1:length(obj.data)
                % randomly select a basis  
                b=randi([1 2]);
                selectedbases=[ selectedbases b ];
                % corresponding angles
                A=obj.basis(b,:);
                % map data bit to photon
                S=[S A(obj.data(i)+1) ];
            end
        end
    end   
end

