1
2
3
1
2
3
4
1
2
3
4
package main
import (
"fmt"
"math/rand"
"time"
)
const (
BIT_0 = iota
BIT_1 = iota
)
type QuantumBit struct {
Polarization int
ValueOfBit int
}
type QuantumResult struct {
AliceBitCounts []int
AliceBaseCount []int
BobBItCount []int
BobBaseCount []int
SharedBits []int
}
var (
QBIT QuantumBit
QRES QuantumResult
Qubit = make([]*QuantumBit, 16)
SharedQubit = make([]int, 0)
Alices_Bits = make([]int, 16)
Alices_Bases = make([]int, 16)
Bobs_Bits = make([]int, 16)
Bobs_Bases = make([]int, 16)
)
func init() {
rand.Seed(time.Now().UnixNano())
}
func (Qubit *QuantumBit) Step_3_MeasurePolarization(pol int) int {
if pol == Qubit.Polarization {
return Qubit.ValueOfBit
} else {
return rand.Intn(2)
}
}
func Setup_Call_Alice() {
for i := 0; i < 16; i++ {
polarization := rand.Intn(2)
value := rand.Intn(2)
Qubit[i] = &QuantumBit{
polarization,
value,
}
}
for idx, qubit := range Qubit {
basis := rand.Intn(2)
Alices_Bases[idx] = basis
Alices_Bits[idx] = qubit.Step_3_MeasurePolarization(basis)
}
QRES.AliceBaseCount = Alices_Bases
QRES.AliceBitCounts = Alices_Bits
}
func Setup_Call_Bob() {
for idx, qubit := range Qubit {
basis := rand.Intn(2)
Bobs_Bases[idx] = basis
Bobs_Bits[idx] = qubit.Step_3_MeasurePolarization(basis)
}
QRES.BobBItCount = Bobs_Bits
QRES.BobBaseCount = Bobs_Bases
}
func FinalCallCheckAndVerifyBits() {
for i := 0; i < 16; i++ {
if Alices_Bases[i] == Bobs_Bases[i] {
fmt.Println("[+]-[QSTAT]-[+] => Found equal bit...")
SharedQubit = append(SharedQubit, Alices_Bits[i])
}
}
QRES.SharedBits = SharedQubit
}
func main() {
Setup_Call_Alice()
Setup_Call_Bob()
FinalCallCheckAndVerifyBits()
fmt.Println("Alice's bits:", QRES.AliceBitCounts)
fmt.Println("Alice's bases:", QRES.AliceBaseCount)
fmt.Println("Bob's bits:", QRES.BobBItCount)
fmt.Println("Bob's bases:", QRES.BobBaseCount)
fmt.Println("Shared bits:", QRES.SharedBits)
}
[+]-[QSTAT]-[+] => Found equal bit...
[+]-[QSTAT]-[+] => Found equal bit...
[+]-[QSTAT]-[+] => Found equal bit...
Alice's bits: [0 0 0 0 0 0 0 1 1 0 0 0 0 1 1 0]
Alice's bases: [0 0 1 0 1 1 0 0 0 1 1 1 0 1 1 0]
Bob's bits: [1 1 0 0 0 1 0 1 1 1 1 1 1 1 0 1]
Bob's bases: [1 0 1 0 1 0 0 1 0 0 0 1 1 0 1 0]
Shared bits: [0 0 0]
1
2
3
4
1
2
3
4
1
2
3
4
1
2
3
4
1
2
3
4
1
2
3
4
1
2
3
1
2
3
4
1
2
3