Cryptography Stack Exchange is a question and answer site for software developers, mathematicians and others interested in cryptography. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm looking for a simulation of the Quantum Key Distribution protocol. Does anyone here have one that they could recommend?

share|improve this question

There are several kind of quantum key distribution (QKD) protocols as of today. Are you looking for a particular one?

The best known QKD protocol goes by the name BB84 after its inventors Bennett and Brassard and the year in which they presented their work. Searching on the Internet, I found this link with a simulation that looks fairly nice and introductory.

As such, programming (at least) an ideal version of the BB84 protocol is not difficult. By ideal I mean that Alice's source, Bob's receiver are perfect, and the channel is not only without Eve but also does not absorb or distort the information carriers (in case you do not have any background in quantum physics, you could also read section 2 of this paper that serves to explain the operation of BB84 to even non-scientists).

Otherwise, with the following steps you can simulate BB84 on your own:

  1. Generate two random bit-sequences of length 2N and N for Alice and Bob, respectively. At the end of the protocol, Alice and Bob would share a symmetric and secret key of length n $\approx$ N/2 distilled from these bit sequences. The next 3 steps can be assumed to operate in a loop from 1 to N.

  2. Alice uses 2 bits at a time to generate one of four quantum states denoted by Q and having the values H, V, D, A randomly (use the mapping H=00, V=01, D=10, A=11 for the BB84 protocol).

  3. A state prepared by Alice arrives in Bob as it is, i.e., without being subjected to loss or noise.

  4. Bob uses his bits to choose the basis B randomly, i.e., B=0=HV basis or B=1=DA basis with equal probability. Now comes the only piece of logic you need to understand. In a given instance, assume Bob's chosen basis shares a non-empty string with Alice's chosen state, e.g., Q=D and B=DA (this technically means they used the same basis). In such an instance, Bob's outcome, or the bit obtained by him due to the measurement on the quantum state, is deterministic and equal to the 2nd bit of Alice (which would be 1 in this case). On the other hand, if the basis do not match, e.g., Q=V and B=DA again, Bob's outcome could be either 0 or 1.

  5. After Bob has finished measuring all N states, he publicly reveals his basis choice but not the outcomes he obtained. Alice applies the same logic as in the previous step -- she examines all N instances to locate those where her basis matched with that of Bob. She then informs Bob to keep these outcomes only in such instances while choosing the corresponding bits from her bit-sequence. This is the secret key.

share|improve this answer

Actually recently I found out about a complete QKD simulation toolkit that has become available, accessible online via this link, QKD simulator.

It is a parameter-based simulator, so different scenarios (qubit numbers, Eve's influence, etc.) can be set up and simulated.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.