qc.reset(3);
qc.discard();
var a = qint.new(1, 'alice');
var fiber = qint.new(1, 'fiber');
var b = qint.new(1, 'bob');
function random_bit(q) {
q.write(0);
q.had();
return q.read();
}
// Generate two random bits
var send_had = random_bit(a);
var send_val = random_bit(a);
// Prepare Alice's qubit
a.write(0);
if (send_val) // Use a random bit to set the value
a.not();
if (send_had) // Use a random bit to apply HAD or not
a.had();
// Send the qubit
!fiber.exchange(a);
// Activate the spy
var spy_is_present = true;
if (spy_is_present) {
var spy_had = 0;
if (spy_had)
fiber.had();
var stolen_data = fiber.read();
fiber.write(stolen_data);
if (spy_had)
fiber.had();
}
// Receive the qubit
!var recv_had = random_bit(b);
fiber.exchange(b);
if (recv_had)
b.had();
var recv_val = b.read();
// Now Alice emails Bob to tell
// him her choice of operations and value.
// If the choice matches and the
// value does not, there's a spy!
if (send_had == recv_had)
if (send_val != recv_val)
qc.print('Caught a spy!\n');
는 지금 읽고 있는 책에 나오는 코드. 정확히는 양자컴퓨터 시물레이터이고, 그냥 라이브러리처럼 사용한다(실제 양자컴도 이렇게 되리라 봄)
저자들이 셋인데, 코드의 질은 똥임. 보면 이해 안가는 부분이 한두개가 아녀.
코드리뷰 보내줘야 될듯.
책을 쓰는 넘이라도, 생각을 코드로 잘 표현하는 진짜 프로그래머는 드물다.
끗.
잘은 모르겠지만 데이터 변조를 체크하는건가