├── P5jsVersion └── sketch.js ├── README.md └── docs ├── _config.yml ├── index.html └── sketch.js /P5jsVersion/sketch.js: -------------------------------------------------------------------------------- 1 | var w = 1000; 2 | var h = 300; 3 | var rt2 = Math.sqrt(2); 4 | var countqubits = 0; 5 | var keysize = 0; 6 | 7 | function qubit(x,y,basis){ 8 | this.x=x; 9 | this.y=y; 10 | this.basis = basis; 11 | this.state = Math.floor(2*Math.random()); 12 | this.renderQubit = function(){ 13 | stroke(255); 14 | strokeWeight(3); 15 | ellipse(this.x,this.y,20,20); 16 | } 17 | this.renderSpin = function(measureBasis){ 18 | stroke(255); 19 | strokeWeight(2); 20 | if (this.basis==0){ 21 | if (this.state==0){ 22 | line(this.x,this.y-10,this.x,this.y+10) 23 | } 24 | else if (this.state==1){ 25 | line(this.x-10,this.y,this.x+10,this.y) 26 | } 27 | } 28 | else if (this.basis==1){ 29 | if (this.state==0){ 30 | line(this.x-10/rt2,this.y-10/rt2,this.x+10/rt2,this.y+10/rt2) 31 | } 32 | else if (this.state==1){ 33 | line(this.x+10/rt2,this.y-10/rt2,this.x-10/rt2,this.y+10/rt2) 34 | } 35 | } 36 | } 37 | this.updatePos=function(dx,dy){ 38 | this.x+=dx; 39 | this.y+=dy; 40 | } 41 | this.setBasis=function(basis){ 42 | if(basis!=this.basis){ 43 | this.basis=basis; 44 | this.state = Math.floor(2*Math.random()); 45 | } 46 | } 47 | } 48 | 49 | function detector_emitter(x,y){ 50 | this.x=x; 51 | this.y=y; 52 | this.basis = Math.floor(2*Math.random()); 53 | this.updateBasis = function(){ 54 | this.basis = Math.floor(2*Math.random()); 55 | } 56 | this.renderBasis = function (){ 57 | stroke(255); 58 | strokeWeight(4); 59 | if (this.basis==0){ 60 | line(this.x,this.y-15,this.x,this.y+15); 61 | line(this.x-15,this.y,this.x+15,this.y); 62 | } 63 | else if (this.basis==1){ 64 | line(this.x-15/rt2,this.y-15/rt2,this.x+15/rt2,this.y+15/rt2); 65 | line(this.x+15/rt2,this.y-15/rt2,this.x-15/rt2,this.y+15/rt2); 66 | } 67 | } 68 | } 69 | 70 | 71 | var q = []; 72 | var a = new detector_emitter(w/9,h/2); 73 | var b = new detector_emitter(8*w/9,h/2); 74 | var key=" "; 75 | 76 | function setup() { 77 | createCanvas(w, h); 78 | background(0); 79 | noFill(); 80 | stroke(255,0,0); 81 | strokeWeight(5); 82 | 83 | frameRate(70); 84 | keyDisp = createDiv(''); 85 | eff = createDiv(''); 86 | q.push(new qubit(a.x,a.y,a.basis)); 87 | 88 | keyDisp.html("Key = "+key); 89 | eff.html("Efficiency = 0%"); 90 | 91 | time = createSlider(25, 750, 500); 92 | time.position(10,10); 93 | time.style('width', '500px'); 94 | } 95 | function draw() { 96 | if(frameCount%Math.floor(time.value())==0){ 97 | a.updateBasis(); 98 | q.push(new qubit(a.x,a.y,a.basis)); 99 | } 100 | background(0); 101 | a.renderBasis(); 102 | b.renderBasis(); 103 | for(i=0;i 2 | 3 | 4 | 10 | 11 | 12 | 13 | BB84 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /docs/sketch.js: -------------------------------------------------------------------------------- 1 | var w = 1000; 2 | var h = 300; 3 | var rt2 = Math.sqrt(2); 4 | var countqubits = 0; 5 | var keysize = 0; 6 | 7 | function qubit(x,y,basis){ 8 | this.x=x; 9 | this.y=y; 10 | this.basis = basis; 11 | this.state = Math.floor(2*Math.random()); 12 | this.renderQubit = function(){ 13 | stroke(255); 14 | strokeWeight(3); 15 | ellipse(this.x,this.y,20,20); 16 | } 17 | this.renderSpin = function(measureBasis){ 18 | stroke(255); 19 | strokeWeight(2); 20 | if (this.basis==0){ 21 | if (this.state==0){ 22 | line(this.x,this.y-10,this.x,this.y+10) 23 | } 24 | else if (this.state==1){ 25 | line(this.x-10,this.y,this.x+10,this.y) 26 | } 27 | } 28 | else if (this.basis==1){ 29 | if (this.state==0){ 30 | line(this.x-10/rt2,this.y-10/rt2,this.x+10/rt2,this.y+10/rt2) 31 | } 32 | else if (this.state==1){ 33 | line(this.x+10/rt2,this.y-10/rt2,this.x-10/rt2,this.y+10/rt2) 34 | } 35 | } 36 | } 37 | this.updatePos=function(dx,dy){ 38 | this.x+=dx; 39 | this.y+=dy; 40 | } 41 | this.setBasis=function(basis){ 42 | if(basis!=this.basis){ 43 | this.basis=basis; 44 | this.state = Math.floor(2*Math.random()); 45 | } 46 | } 47 | } 48 | 49 | function detector_emitter(x,y){ 50 | this.x=x; 51 | this.y=y; 52 | this.basis = Math.floor(2*Math.random()); 53 | this.updateBasis = function(){ 54 | this.basis = Math.floor(2*Math.random()); 55 | } 56 | this.renderBasis = function (){ 57 | stroke(255); 58 | strokeWeight(4); 59 | if (this.basis==0){ 60 | line(this.x,this.y-15,this.x,this.y+15); 61 | line(this.x-15,this.y,this.x+15,this.y); 62 | } 63 | else if (this.basis==1){ 64 | line(this.x-15/rt2,this.y-15/rt2,this.x+15/rt2,this.y+15/rt2); 65 | line(this.x+15/rt2,this.y-15/rt2,this.x-15/rt2,this.y+15/rt2); 66 | } 67 | } 68 | } 69 | 70 | 71 | var q = []; 72 | var a = new detector_emitter(w/9,h/2); 73 | var b = new detector_emitter(8*w/9,h/2); 74 | var key=" "; 75 | 76 | function setup() { 77 | createCanvas(w, h); 78 | background(0); 79 | noFill(); 80 | stroke(255,0,0); 81 | strokeWeight(5); 82 | 83 | frameRate(70); 84 | keyDisp = createDiv(''); 85 | eff = createDiv(''); 86 | q.push(new qubit(a.x,a.y,a.basis)); 87 | 88 | keyDisp.html("Key = "+key); 89 | eff.html("Efficiency = 0%"); 90 | 91 | time = createSlider(25, 750, 40); 92 | time.position(10,10); 93 | time.style('width', '500px'); 94 | } 95 | function draw() { 96 | if(frameCount%Math.floor(time.value())==0){ 97 | a.updateBasis(); 98 | q.push(new qubit(a.x,a.y,a.basis)); 99 | } 100 | background(0); 101 | a.renderBasis(); 102 | b.renderBasis(); 103 | for(i=0;i