Last active
January 19, 2020 13:11
-
-
Save yutakahashi114/c6be0bee4f90ca0a2d9ea9c93220b124 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cirq | |
from alice import Alice | |
from bob import Bob | |
from network import Network | |
def main(): | |
# 使用するbit数を決める | |
bit_count = int(input('Bit count : ')) | |
alice = Alice(bit_count) | |
bob = Bob() | |
network = Network() | |
for index in range(bit_count): | |
# ビットの初期値を決め、ランダムな基底でエンコードする | |
circuit, qubits = network.send(alice.encode_function(index)) | |
# アリスの手元のビットを観測する | |
alice.measure_qubits(circuit, qubits[0:2]) | |
# ボブに送ったビットに反映させる | |
network.reflect_measure_results(circuit, qubits) | |
# ランダムな基底でデコードする | |
bob.measure_qubits(circuit, qubits[2]) | |
# アリスとボブは互いに何番目のビットをどちらの基底でエンコード・デコードしたか教え合う | |
# 基底が一致したビットを抽出し、秘密鍵とする | |
alice.set_secret_key(bob.decode_gates) | |
bob.set_secret_key(alice.encode_gates) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment