// bob implements all the necessary functionality for Bob's part of the // communication func bob(channel chan []*big.Int, stop chan int, conn net.Conn) { fmt.Printf("Bob is waiting for a prime number from Alice...") receive(channel, conn) primeSlice := <-channel prime := primeSlice[0] if !(*prime).ProbablyPrime(4) { fmt.Printf("Alice prime number is probably not prime") } fmt.Println("Bob is waiting for the encrypted message from Alice...") receive(channel, conn) x := <-channel b, bInv := shamir.GenerateExponents(prime) fmt.Println("Bob computes a secret Exponent and the inverse of it") fmt.Printf("Bob's secret exponent:\n%x\n", b) fmt.Printf("Bob's secret inverse:\n%x\n\n", bInv) fmt.Println("Bob received the encrypted message from Alice and is now" + " encrypting it too!") y := shamir.CalculateParallel(x, b, prime) fmt.Printf("Bob now sends the double-encrypted message back to "+"Alice:\n%x\n\n", shamir.GlueMessage(y)) channel <- y send(channel, conn) fmt.Println("Bob is waiting for Alice's answer...") receive(channel, conn) x = <-channel fmt.Println("Bob received the second message from Alice and is now " + "decrypting it!") y = shamir.CalculateParallel(x, bInv, prime) fmt.Println("Bob decrypted the following message from Alice: " + shamir.GlueMessage(y)) stop <- 1 }
func send(channel chan []*big.Int, conn net.Conn) { _, err := conn.Write([]byte(shamir.GlueMessage(<-channel))) checkError(err) }