ラベル BB84 の投稿を表示しています。 すべての投稿を表示
ラベル BB84 の投稿を表示しています。 すべての投稿を表示

2026年5月24日日曜日

量子鍵配送プロトコルBB84での混合状態

Mixed States in the BB84 Quantum Key Distribution Protocol

At first glance, it may seem that if a perfectly noise-tolerant quantum computer existed, quantum computations would remain in pure states from beginning to end, making mixed states unnecessary. However, this is a misconception. Even in such an ideal quantum computer, mixed states can play an important and practical role.

I came to understand this through the BB84 quantum key distribution (QKD) protocol. Using the dynamic-circuit functionality available in Qiskit, I was able to verify this behavior experimentally on an IBM Quantum processor, ibm_kingston.

Specifically, when an eavesdropper is present, the BB84 protocol predicts a theoretical error-detection rate of 25%. Running the protocol on the quantum computer yielded an observed error rate of 25.9%, in close agreement with the theoretical expectation.

This experiment demonstrates that mixed states are not merely artifacts of noise or imperfections. Rather, they are an essential and useful concept in quantum information processing, even when quantum operations themselves are ideally coherent.

【要旨】これまで、密度行列に関する記事を2つ(こちらとこちらに)書いた。それによれば、もしも、完璧なノイズ耐性量子コンピュータがあれば、量子計算は最初から最後まで、純粋状態を保たれるので、混合状態は考える必要がないように思われた。しかし、それは誤りであり、たとえ、そのような量子コンピュータであっても、混合状態は有効に利用されるのである。そのことを、量子鍵配送プロトコルBB84を例として理解した。Qiskitに装備されている動的量子回路機能を用いて、IBM Quantum実機で確かめることもできた。


→Dr. Peter Lee, Dr. M.S. Qureshiからのこちらのコメントもここにあります。


🟢量子鍵配送プロトコルBB84の仕組み

 すでに、過去の記事(こちらとこちら)で詳細を述べたが、短く言えば以下のようになるだろう。


-----「Aliceは、古典ビット(0か1)と、使用する基底(2種)をそれぞれランダムに選んで決定する。そして、選択した基底における、古典ビットに対応する状態ベクトルをBobへ送る。

 Bobは、Aliceとは全く独立に選んだ基底で、受信した量子状態を測定する。もしもAliceとBobの選んだ基底が一致していれば、両者は同一の古典ビットを得ることになる。

 しかし、ここでEveが盗聴を試みる場合、Eveは自身がランダムに選んだ基底でAliceの量子状態を測定してしまう。そして、Eveは盗聴を隠蔽するため、自身の測定結果に応じて量子状態を再度生成してBobへ送らざるを得ない。これは、”量子状態複製不可定理”による。しかし、Eveの選んだ基底がAliceのものと異なる場合(1/2の確率)、BobへはAliceが送ったものとは異なる(変質した)量子状態が届くことになる。

 その結果、後線でAliceとBobが互いの基底を照合し、『基底が一致していたケース』のみを抽出したとしても、そのうち1/4(25%)の確率で二人の古典ビットが不一致を起こす。 AliceとBobはこのエラー率を検出することで、Eveの盗聴を確実に察知できる。」-----


 たとえば、Aliceが連続して多数回、量子ビットを送信した場合の動きの例を以下に示す。盗聴がない場合と、盗聴がある場合について、その先頭部分を示す。


=== 1. 盗聴がない場合 (Eve: NO) ===

試行 1: Alice基底=X(0), Bob基底=X -> Bob測定=0 | 一致 (鍵採用)

試行 2: Alice基底=X(0), Bob基底=X -> Bob測定=0 | 一致 (鍵採用)

試行 3: Alice基底=X(0), Bob基底=Z -> Bob測定=0 | 不一致 (廃棄)

試行 4: Alice基底=X(0), Bob基底=X -> Bob測定=0 | 一致 (鍵採用)

試行 5: Alice基底=X(0), Bob基底=Z -> Bob測定=1 | 不一致 (廃棄)

試行 6: Alice基底=Z(1), Bob基底=X -> Bob測定=0 | 不一致 (廃棄)

試行 7: Alice基底=X(1), Bob基底=Z -> Bob測定=1 | 不一致 (廃棄)

試行 8: Alice基底=Z(1), Bob基底=X -> Bob測定=0 | 不一致 (廃棄)

試行 9: Alice基底=Z(0), Bob基底=X -> Bob測定=1 | 不一致 (廃棄)

試行 10: Alice基底=X(1), Bob基底=Z -> Bob測定=0 | 不一致 (廃棄)

. . . . . . . . . .

【結果】Aliceの鍵 : 0000101000111110110111100000101011011001110100111111

【結果】Bobの 鍵 : 0000101000111110110111100000101011011001110100111111

エラー率: 0.0%


=== 2. 盗聴がある場合 (Eve: YES) ===

試行 1: Alice基底=Z(0), Bob基底=X -> Bob測定=1 | 不一致 (廃棄)

試行 2: Alice基底=Z(1), Bob基底=X -> Bob測定=1 | 不一致 (廃棄)

試行 3: Alice基底=X(1), Bob基底=X -> Bob測定=0 | 一致 (鍵採用)

試行 4: Alice基底=X(0), Bob基底=X -> Bob測定=0 | 一致 (鍵採用)

試行 5: Alice基底=X(0), Bob基底=Z -> Bob測定=1 | 不一致 (廃棄)

試行 6: Alice基底=X(0), Bob基底=Z -> Bob測定=1 | 不一致 (廃棄)

試行 7: Alice基底=X(0), Bob基底=X -> Bob測定=1 | 一致 (鍵採用)

試行 8: Alice基底=X(1), Bob基底=X -> Bob測定=1 | 一致 (鍵採用)

試行 9: Alice基底=X(1), Bob基底=X -> Bob測定=0 | 一致 (鍵採用)

試行 10: Alice基底=X(0), Bob基底=Z -> Bob測定=0 | 不一致 (廃棄)

. . . . . . . . . .

【結果】Aliceの鍵 : 10011101100010110010001110110010011100110100

【結果】Bobの 鍵 : 00110101100011110010101111010111001100110000

エラー率: 25.0%


🟢混合状態はどこに現れ、利用されるか

 Aliceは「基底 Z= {|0>, |1>} または基底 X = {|+>, |->}」と「古典ビット(0または1)」をそれぞれ全くランダムに選び、以下に示す可能な4つの状態のいずれか1つを送信することになる。


 すなわち、送信される側のBobや、途中で盗聴を試みるEveの視点では、彼らはAliceがどの基底を使ったかを事前には知らない。したがって、彼らにとって届く量子状態は、4つの純粋状態が等確率(各 25%)で混ざり合った最大混合状態(Maximal Mixed State)になる。それを密度行列ρで表すと以下のようになる。


ρ = (|0><0| + |1><1| + |+><+| + |-><-| ) /4 = (1/2)I (Iは単位行列)


 このことは、Aliceが2つの基底をランダムに行き来することで、「基底情報を知らないEveが、その量子ビットから正しくビット情報を取り出すことはできない」ことを意味する。あるいは、

「Eveがどの基底で待ち伏せしても、見つからず盗聴することは不可能」であることを示している。これが混合状態の正体であると言える。


🟢Qikitの動的量子回路機能でBB84を構成する

 以前は、量子回路は「測定」して得られた古典ビット情報に依存して、その後の量子回路を動的に変更や追加することができなかった。しかし、現在のQiskitではそれが可能なので、上に述べた混合状態を含む量子回路を、一つのジョブとして実行することができ、非常に便利である。その回路図は以下の通りである。

 

 Alice, Eve, およびBobがそれぞれ、どの基底を採用したか、また、測定結果はどうだったを見るため、量子回路の途中で、それぞれ2回づつ測定を行っている。それらの結果を6個の古典レジスタに格納し、その値に応じて、必要な量子ゲートを動的に追加している。


🟢IBM Quantumマシン実機(ibm_kingston)による実行結果

 以上の量子回路を、Open Planで利用可能なIBM 量子コンピュータ実機で実行した結果を以下に示す。盗聴なし、盗聴ありの両ケースとも、ノイズによる若干の影響がみられたが、ほぼ、理論値通りの結果が得られた。


==================================================

 【 Eveによる盗聴なし】IBM Quantum ibm_kingston usage = 2s

==================================================

  採用鍵の長さ: 504 / 1000 shots

  AliceとBobの選択基底が合致した先頭30個について:

   Aliceの鍵 : [1 1 0 1 0 1 0 1 0 0 1 0 1 0 0 0 1 1 1 1 1 1 0 0 1 0 1 0 1 0]

   Bobの鍵  : [0 1 0 1 0 0 0 1 0 0 1 0 1 0 0 0 1 1 1 1 0 1 0 0 1 0 1 0 1 0]

  実機エラー率: 1.4% (理論値: 0% + 実機ノイズ)

==================================================


==================================================

 【 Eveによる盗聴あり】IBM Quantum ibm_kingston usage = 2s

==================================================

  採用鍵の長さ: 455 / 1000 shots

  AliceとBobの選択基底が合致した先頭30個について:

   Aliceの鍵 : [0 1 1 1 1 0 0 1 1 1 1 1 0 0 0 1 1 1 1 0 1 1 1 1 0 0 1 1 1 0]

   Bobの鍵  : [1 1 1 0 1 0 0 0 1 1 1 1 0 0 0 0 1 0 0 0 1 1 0 1 0 0 1 1 1 0]

  実機エラー率: 25.9% (理論値: 25% + 実機ノイズ)

==================================================


2023年5月28日日曜日

Confirmation of quantum key distribution protocol BB84 with smartphone app (supplement)

[Abstract] BB84 (quantum key distribution protocol) is excellent among the limited applications when using a single qubit (that is, not using quantum entanglement). I've written an article about this in the past, but I'll add it here to make it even clearer. This BB84 is also a good example for learning "measurement of quantum states by orthonormal basis".

●What is BB84 (reconfirmation)
BB84 is a method in which 1/4 of Alice's classical bit string of length 4n is used as a secure key between them without sending it directly to Bob. Alice randomly selects an orthonormal basis for each bit of the classical bit string of length 4n, and sends the basis vector (quantum state vector) corresponding to that bit to Bob. Importantly, a method is included to determine if this transmission has been intercepted by a third party, Eve.

●Blog articles written in the past
I wrote the BB84 method in detail in the blog post below. (The figure is also reproduced.)
https://sparse-dense.blogspot.com/2022/11/bb84.html



Now, when I read it again, I didn't find any particular mistakes, but I felt that the explanation was a little lacking, so I added the following section "How to actually configure the BB84".

----------(Supplementary explanation added)----------------------------
●How to actually configure the BB84
The theory is now explained. From the above explanation, the number of times Alice and Bob's chosen bases match is 2n. The resulting bit string measured by Bob on that matched base matches the bitstring Alice has. So, assuming no eavesdropping, Alice does not send the 2n long bit string to Bob and they can both share the bit string as a key.

However, in reality, Alice is sending the basis quantum state vector to Bob, so we have to check whether it is wiretapped. Therefore, both parties send each other n-length bit strings, which is half of this 2n-length bit string, by "unencrypted normal communication" and confirm the degree of matching. If they match perfectly, it can be said that there is no eavesdropping. On the other hand, if 1/4 of them do not match, it can be said that there was wiretapping. (It takes advantage of the fact that eavesdropping requires measuring its qubit (quantum state vector), which changes the quantum state to be sent to Bob.)

If we find no eavesdropping, we can safely use the other half of the matched 2n long bit string as the key. (Actually, 2n lengths match, but half of them may be known to others due to the above-mentioned normal communication.)

---------------------------------------------------------------------

2022年11月10日木曜日

My understanding of the Quantum Key Distribution Protocol Ekert (E91)

Japanese abstract
前報は、単一量子ビットを利用する量子鍵配送プロトコルBB84の説明であったが、今回は、「もつれた状態」の2つの量子ビット対のストリームを利用した安全な鍵配送プロトコルEkertを説明する。これは、すでに本ブログで紹介した「Bellのテスト(Bellの不等式)」に基づいている。このような量子ビットを受け取った2者が、それぞれランダムに選択した正規直交基底を使ってそれを測定する。その結果の両者の古典ビット列の一致度が盗聴の有無を明らかにする。この記事は、Prof. Chris Bernhardtの著書[1]に基づいているが、小生が理解した内容を独自の観点からまとめたものである。

English Abstract
In my previous article, I described the quantum key distribution protocol BB84, which uses a single qubit. Here I describe the Ekert, a secure key distribution protocol that uses a stream of two qubit pairs in an entangled state. This is based on Bell's test (Bell's inequality) which was already introduced in this blog. Two parties that receive such qubits each measure them using randomly chosen orthonormal bases. The degree of matching between the two resulting classical bit strings reveals the presence or absence of eavesdropping. This article is based on Prof. Chris Bernhardt's book [1] and explains the Ekert from my own point of view.

●Measure qubits in different orthonormal bases
First, let's see what happens when we measure the received qubits in a different orthonormal basis than the one from the sender. In the following, for simplicity, the orthonormal bases will simply be referred to as bases. Here, one is randomly selected from the three types of bases shown in Fig 1. Bases D000, D120, and D240 correspond to setting the orientation of measurement apparatus to due north, southeast, and southwest, respectively.
    Next, Fig. 2 summarizes how each ket vector (vertical vector) of the basis used for measurement on the transmitting side is expressed in a different basis. In general, the state of a qubit will be a linear combination of the ket vectors of the chosen basis. The probability that a measurement result falls to a ket vector is the square of the coefficient of that ket vector.
    As already shown in Bell's test, Fig. 2 reveals an important point. If the measurement result in the original basis is 0 (falling to the first ket vector), it will be 0 with a probability of 1/4 when measured in another different basis. Also, if the measurement in the original basis is 1 (falling to the second ket vector), it will be 1 again with a probability of 1/4 when measured in a different basis.
    That is, there is a 1/4 probability that a measurement on the original basis agrees with another measurement on a different basis. This is a theoretical value, but if you send enough qubits and measure them, it should approach this probability infinitely.

●How the quantum key distribution protocol Ekert works
With the above preparation, we can describe the Ekert protocol. Suppose we send a stream of two qubit pairs to Alice and Bob. Importantly, paired qubits are always in the entangled state 
(1/√2) |↑〉|↑〉+(1/√2) |↓〉|↓〉.
 Both will each receive one of the pair. My description will be made below with reference to Fig.3.
    Note that the entangled states
(1/√2) |↑〉|↑〉+(1/√2) |↓〉|↓〉 
        and  
(1/√2) |↘︎〉|↘︎〉+(1/√2) |↖︎〉|↖︎〉
are exactly the same. This fact is proven in reference [1], but is omitted here.
    Suppose that Alice performs measurements on the selected basis D120 (see Figure 1) before Bob does. For example, if the result is 0 (ie, |↘︎〉|↘︎〉), Bob's qubit will also be |↘︎〉 because of the entangled state. Bob measures it on a randomly chosen basis. If the basis is different from Alice's, he gets 0 with probability 1/4, from the fact already revealed in Fig2. Similarly, if Alice's measurement result is 1, Bob's measurement result will be 1 with probability 1/4.
    Now, after all qubits have been processed, Alice and Bob exchange their lists of bases (not measurement results) of their choice. In that case, secure communication is not particularly required. Since there are three types of bases that can be selected by both, the two bases match in 1/3 of the total cases. Qubits always give the same result when measured on the same basis. Therefore, If no eavesdropping has occurred, the measurements with their agreed bases can be the common key.

●Why can eavesdropping be detected?
Now consider the case where Eve eavesdrops on an entangled qubit. As I mentioned in the previous BB84 protocol explanation, Eve always needs to set a certain base and use it to make measurements. If measured in such a way, the entanglement will disappear immediately. As a result, the probability that Alice's and Bob's classical bits match will change. For example, if Eve eavesdrops before Alice's measurements, we find that the entanglement disappears and the probability that Alice and Bob's classical bits match increases to 3/8. In other words, when the bases of Alice and Bob are different, if the probability that the classical bits of both match is 1/4, it can be said that there was no eavesdropping.
Acknowledgments
Thanks to Prof. Chris Bernhardt, author of reference [1], for kindly answering some of my questions about entanglement and Bell's inequality.
    I used the illustration (icon) of the Qni quantum circuit simulator[2] to show the qubit vectors..

References
[1] Chris Bernhardt, “Quantum Computing for Everyone”, MIT Press, 2020 

2022年11月4日金曜日

量子鍵配送プロトコルBB84をスマホアプリで確認

abstract: 理論上(計算上)は明確になっている事項でも、実際に一歩づつトレースして理解することは意味があると考えました。AliceからBobへ、長い古典ビット列を送信することを想定します。問題は、それをEveに盗聴される可能性です。しかし、量子コンピューティングの世界では、Eveが盗聴すれば必ず露呈するという、量子鍵配送プロトコルBB84があります。そのエッセンスを、自作したスマホアプリを使って説明を試みました。

【改訂】2023-05-28、後半に「実際にBB84を構成するには」を追加し補足した。

Check the quantum key distribution protocol BB84 with a smartphone app
Even if the conclusion is known in theory, it is useful to deepen understanding by actually proceeding step by step. Now imagine sending a long string of classical bits from Alice to Bob. The problem is that it can be eavesdropped on by Eve. However, in the world of quantum computing, there is a quantum key distribution protocol (BB84) that if Eve eavesdrops, it will always be revealed. This time, I will explain the essence using a self-made smartphone app.

●量子鍵配送プロトコルBB84の概要
 このプロトコルは1984年に発表されたもので、量子ビットの重ね合わせ(Quantum Superposition)を利用している。ここでは、単一量子ビットをひとつづゝ連続して送信するので、量子もつれ(Quantum Entanglement)は無い。(量子もつれ状態の量子ビット対の送信用には、Ekertプロトコルがあるが、それは別記事とする。)

 図1は、BB84の原理を確認するためのアプリである。量子シミュレータではない。Aliceは、例えば古典ビット2048個(これを暗号鍵にするつもり)の4倍の8192個を用意するが、これをそのままBobへ送信はしない。代わりに、2種類の2次元正規直交基底(以後、単に基底と呼ぶ)HかVを各ビット毎にランダムに選択して、ビット値に対応する、基底のケットベクトル(縦ベクトル)を送信する。古典ビット0と1は、それぞれ、基底の1番目と2番目のケットベクトルに対応させている。つまり、量子ビット(の状態ベクトル)を送信するのである。具体例は後で示す。
 Bobは、受信した量子ビット毎に、ランダムに(Aliceとは無関係に)同様にHかVを選択して、それによって量子ビットを「測定」する。その結果として、全部の受信が完了後には、Aliceと同じ長さの古典ビット列(8192個で構成)を得る。AliceとBobの持つこの古典ビット列の合致度によって、盗聴の有無を判定できるのである。

  Eveが盗聴する場合、受信量子ビットをそのままBobへ転送して自分はそのコピーを盗聴する、ということは量子原理から不可能である。盗聴するには、受信した量子ビットを必ず「測定」し、その結果としての量子ビットをBobへ転送するしかない。測定前の量子ビットは、(日常思考からは不思議なことだが)量子基本原理として、0に対応するか1に対応するかは決まらない。また、測定するには、どの基底を用いるかを決める必要がある。基底の選択によって0か1かに決まる確率は変化するが、Eveにとっては、ランダムに基底を選択する以外に方策がない。

●正規直交基底と量子ビットの重ね合わせと測定
 上で述べた基底とその測定について、具体例で説明する。ここで選択できる基底VとHは以下のようなものである。
 一般に量子ビットは、基底(|u>, |v>)を用いる場合、以下のような状態にある。これは量子重ね合わせ状態(Quantum Superposition)と呼ばれる。そして測定を行うと|u>か|v>のどちらかに確定する。つまり、0か1かになる。その確率は、それぞれの係数の2乗で決まる。
 ある量子ビットに対して同一基底を適用するのならば、何度測定しても必ず同一の結果になる。しかし、異なる基底で計測した場合は、0と1のどちらに倒れるかの確率は、基底のケットベクトルの係数(振幅確率)の平方となる。振幅確率の求め方は、参考文献[1]にあるので、それを使って、基底H, Vの場合を計算すると以下のようになる。
 このことから、HとVを使う限り、元の計測と今回の計測で異なる基底が使われる場合は、ちょうど確率0.5(= (±1/√2)の平方)で元の計測結果と同一となることが分かる。そこがポイントである。

●盗聴があったとすれば何が変化するのか
 以上の準備をした上で、盗聴の有無で何が異なるのかを図2で見てみよう。すでに述べた通り、Eveが盗聴するとすれば、Eveは盗聴した量子ビット毎に、ランダムに基底HかVをに選択し、測定しなければならない。その結果として②に示された量子ビット列をBobへ送る。すなわち、Bobは本来の①の量子ビットとは異なる②を受信することになる。
 それにより、Bobの測定結果は本来のものと異なるであろう。Bobの測定結果として得られる古典ビット列は、Aliceが元々設定した古典ビット列と比較される。盗聴されていない場合は、上に述べた手順から、AliceとBobがそれぞれ選択した基底(H, V)は0.5の確率で一致するので、古典ビット列の少なくとも1/2が一致する。さらに、すでに述べた通り、異なる基底で測定したケースでは(量子ビットの重ね合わせにより)、確率0.5で両者の古典ビットが合致する。結局、(1/2)+(1/2)*(1/2) = 3/4 = 0.75の確率で両者の古典ビットは合致する。
 一方、盗聴があった場合は、Eveによる基底選択が加わるので、AliceとBobの基底の一致確率は(1/2)*(1/2)に低下する。そして、基底が一致しない場合のAliceとBobの古典ビットの一致確率は3/8となる。結局、確率(1/4)+(3/8)=5/8 = 0.625でAliceとBobの古典ビットが一致する。従って、最終的にAliceとBobの古典ビットの一致確率が0.75であれば盗聴は無く、0.625であれば盗聴されたと結論付けられる。

●実際にBB84を構成するには
 これで理論は説明された。上の説明から、AliceとBobの選択した基底が一致する回数は2nとなる。その合致した基底でBobが測定した結果のビット列は、Aliceが持っているビット列と一致する。従って、盗聴がないと仮定すれば、Aliceはその2n長のビット列をBobに送らずに、両者がキーとしてそのビット列を共有できる。
 だが、実際には、Aliceは基底の量子状態ベクトルをBobに送信しているのでその盗聴の有無を確認しなければならない。そこで、両者はこの2n長のビット列の半分のn長のビット列を「暗号化しない通常通信」で送り合って、その一致度を確認する。もしも完全に一致すれば盗聴はないと言える。一方、その1/4が一致しなければ盗聴があったと言える。(そこでは、盗聴するにはその量子ビット(量子状態ベクトル)を測定する必要があり、そうすれば、Bobに送られるべき量子の状態は変化することを巧みに利用している。)
 盗聴がないと分かった場合には、合致した2n長のビット列の残りの半分であるn長のビット列をキーとして安全に使える。(実際には2n長が合致しているのだが、上記通常通信により、そのうちの半分は他人に知られている可能性があるためである。)

●AliceとBobの持つ情報の一致度をスマホで計算
 ここでようやく前述のスマホアプリが登場する。今回は、両者の選択基底が異なる場合の振幅確率の平方はいずれの場合も0.5であった。このため、重ね合わせ状態にある量子ビットの測定結果は単にコイントス乱数で決めることができる。ただし、本当は、その乱数が「真の乱数」であることが求められる。スマホの数学ライブラリの乱数でも、非常に多く発生させれば問題は生じないだろう。図3には、Aliceが8192個の古典ビットを乱数で一つづゝ発生させた場合の結果を示している。
 盗聴なしとありの場合の両方とも、AliceとBobの最終的な古典ビットの一致度は、上に述べた数値とほぼ同一(小数点以下3桁まで一致)となった。このことから、BB84の理論通りの結果が得られたと言える。

参考文献
[1] Chris Bernhardt: Quantum Computing for Everyone, The MIT Press, 2020.