前言
最近在看量子通讯的文章,在此记下学习过程和自己的理解。
BB84
在与Alice公开讨论之前, Bob和Eve的地位是相同的。
原理
存在的问题:当Eve和Alice使用相同的正交基时,Eve不会被发现。
简单的matlab仿真
使用Matlab模拟Alice发送数据和Bob接受数据的行为,验证当Eve窃听时,会被明显的发现。
结果:
当Eve不存在时,Bob和Alice选择一样正交基的概率是 ~50%,与之对应的数据的正确率也是 ~50%。
当Eve存在时,Bob和Alice选择一样正交基的概率是 ~50%,与之对应的数据的正确率也是 ~37.5%。
如果不比较正交基,只比较数据的结果,那么就是75%(无Eve)和62.5%(有Eve)。
程序可以分为三个部分:
Alice
- 准备要发送的数据(产生0/1的随机数据串)
- 随机选择正交基
- 确定光子的状态(偏振态 (0,90) 和 (45, 135))
Eve
- 接受数据,并随机选择正交基
- 根据测量结果确定光子的偏振态
- 重新发送光子
Bob
- 接受数据,并随机选择正交基
- 根据测量结果确定光子的偏振态
- Alice对比选择的正交基,比较用相同正交基测量的结果
代码如下:
number_of_data = 100000; %100000000
flag_Eve_intercept = 1;
flag_print_table=0; % if number_of_data larger than 50, no recommend
%% Alice data
alice_data = randi([0,1],[1,number_of_data]);
alice_zeros = length(find(alice_data == 0));
alice_ones = length(find(alice_data == 1));
%% Alice encoding with different basis [H 1, V 2,A 3, D 4] -- [0°, 90°,45°, 135° ] -- [1 0 1 0]
% [H V] = [1 0]; [A, D] = [1, 0]
alice_bases = randi([1,2],[1,number_of_data]);
alice_bases_HV = length(find(alice_bases == 1));
alice_bases_AD = length(find(alice_bases == 2));
photon_state = [0, 90, 45, 135];
% photon_state = [1, 2, 3, 4];
alice_state = zeros(1,number_of_data);
for index_data = 1:number_of_data
% data = 0, basis: H/V H:1, V:0
if alice_data(index_data) == 1 && alice_bases(index_data) == 1
alice_state(index_data) = photon_state(1);
end
% data = 1, basis: H/V H:1, V:0
if alice_data(index_data) == 0 && alice_bases(index_data) == 1
alice_state(index_data) = photon_state(2);
end
if alice_data(index_data) == 1 && alice_bases(index_data) == 2
alice_state(index_data) = photon_state(3);
end
if alice_data(index_data) == 0 && alice_bases(index_data) == 2
alice_state(index_data) = photon_state(4);
end
end
if flag_print_table == 1
fprintf