Skip to content

Instantly share code, notes, and snippets.

@yutakahashi114
Last active January 19, 2020 13:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yutakahashi114/c6be0bee4f90ca0a2d9ea9c93220b124 to your computer and use it in GitHub Desktop.
Save yutakahashi114/c6be0bee4f90ca0a2d9ea9c93220b124 to your computer and use it in GitHub Desktop.
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