コード例 #1
0
ファイル: sockets_alice.go プロジェクト: jwoe/nokey-go
// alice implements all the necessary functionality for Alice's part of the
// communication
func alice(msg string, channel chan []*big.Int, conn net.Conn) {
	prime := shamir.GeneratePrime(PRIMEBITS)
	primeSlice := []*big.Int{prime}
	fmt.Printf("Alice generates a prime number:\n%x\n\n",prime)

	fmt.Printf("Alice sends the prime number to Bob\n")
	channel <- primeSlice
	send(channel, conn)
	fmt.Println("Alice wants to send the following message: " + msg)
	a, aInv := shamir.GenerateExponents(prime)
	fmt.Println("Alice computes a secret Exponent and the inverse of it")
	fmt.Printf("Alice's secret exponent:\n%x\n", a)
	fmt.Printf("Alice's secret inverse:\n%x\n\n", aInv)
	fmt.Println("Alice encrypts her message!")
	var messageInt []*big.Int = shamir.SliceMessage(msg, prime)
	x := shamir.CalculateParallel(messageInt, a, prime)
	fmt.Printf("Alice now sends the encrypted message to Bob:\n%x\n\n",shamir.GlueMessage(x))
	channel <- x
	send(channel, conn)
	fmt.Println("Alice is waiting for Bob's answer...")
	receive(channel, conn)
	x = <-channel
	fmt.Println("Alice received the double-encrypted message and is now" +" decrypting her part!")
	y := shamir.CalculateParallel(x, aInv, prime)
	fmt.Printf("Alice now sends the partly decrypted message to Bob:\n%x\n\n",shamir.GlueMessage(y))
	channel <- y
	send(channel, conn)
}
コード例 #2
0
ファイル: netchan_Bob.go プロジェクト: jwoe/nokey-go
// bob implements all the necessary functionality for Bob's part of the
// communication
func bob(channelReceive chan []*big.Int, channelSend chan []*big.Int, stop chan int) {
	fmt.Printf("Bob is waiting for a prime number from Alice...")
	primeSlice := <-channelReceive

	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...")
	x := <-channelReceive
	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))
	channelSend <- y
	fmt.Println("Bob is waiting for Alice's answer...")
	x = <-channelReceive
	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
}
コード例 #3
0
ファイル: main.go プロジェクト: jwoe/nokey-go
// alice implements all the necessary functionality for Alice's part of the
// communication
func alice(msg string, prime *big.Int, channel chan []*big.Int) {
	fmt.Println("Alice wants to send the following message: " + msg)
	a, aInv := shamir.GenerateExponents(prime)
	fmt.Println("Alice computes a secret Exponent and the inverse of it")
	fmt.Printf("Alice's secret exponent:\n%x\n", a)
	fmt.Printf("Alice's secret inverse:\n%x\n\n", aInv)
	fmt.Println("Alice encrypts her message!")
	var messageInt []*big.Int = shamir.SliceMessage(msg, prime)

	// Parrallel
	//x := shamir.Calculate(messageInt, a, prime)
	x := shamir.CalculateParallel(messageInt, a, prime)

	fmt.Printf("Alice now sends the encrypted message to Bob:\n%x\n\n",
		shamir.GlueMessage(x))
	channel <- x
	fmt.Println("Alice is waiting for Bob's answer...")
	x = <-channel
	fmt.Println("Alice received the double-encrypted message and is now" +
		" decrypting her part!")
	y := shamir.Calculate(x, aInv, prime)
	fmt.Printf("Alice now sends the partly decrypted message to Bob:\n%x\n\n",
		shamir.GlueMessage(y))
	channel <- y
}
コード例 #4
0
ファイル: runtimeTest.go プロジェクト: jwoe/nokey-go
// main implements all necessary functionality to setup the conversation
// between Alice and Bob
func runtimeTest() {
	fmt.Println("CPU 's # ", runtime.NumCPU())

	prime := shamir.GeneratePrime(PRIMEBITS)

	var message string

	//fmt.Print(prime, message)

	a, aInv := shamir.GenerateExponents(prime)

	var time0 time.Time
	var duration time.Duration

	//var words int
	for nCpu := 1; nCpu <= runtime.NumCPU(); nCpu++ {
		runtime.GOMAXPROCS(nCpu)
		fmt.Println("Using CPU # ", nCpu)
		//fmt.Println("\t\t Dauer Normal \t\tDauer Parallel")
		for i := 1; i < 5; i++ {
			word := math.Pow10(i)
			//	words = 10 ^ i
			var buffer bytes.Buffer
			fmt.Print("Chars # ", word*50, "\t\t")
			var j float64 = 0
			for j = 0; j < word; j++ {
				buffer.WriteString("abcdefghijklmnopqrstuvwxzy 1234567890?!, .-#+* ()[]")
			}
			message = buffer.String()

			var messageInt []*big.Int = shamir.SliceMessage(message, prime)

			// Normal
			time0 = time.Now()
			shamir.Calculate(messageInt, a, prime)
			duration = time.Since(time0)

			fmt.Print(float64(duration.Nanoseconds()) / 1000 / 1000)

			// Parrallel
			time0 = time.Now()
			shamir.CalculateParallel(messageInt, a, prime)
			duration = time.Since(time0)
			fmt.Print("\t\t", float64(duration.Nanoseconds())/1000/1000)
			fmt.Println("")

		}

	}

	var messageInt []*big.Int = shamir.SliceMessage("foo", prime)

	x := shamir.CalculateParallel(messageInt, a, prime)
	shamir.GlueMessage(x)

	shamir.Calculate(x, aInv, prime)

}
コード例 #5
0
ファイル: main.go プロジェクト: jwoe/nokey-go
// bob implements all the necessary functionality for Bob's part of the
// communication
func bob(prime *big.Int, channel chan []*big.Int, stop chan int) {
	fmt.Println("Bob is waiting for the encrypted message from Alice...")
	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.Calculate(x, b, prime)
	fmt.Printf("Bob now sends the double-encrypted message back to "+
		"Alice:\n%x\n\n", shamir.GlueMessage(y))
	channel <- y
	fmt.Println("Bob is waiting for Alice's answer...")
	x = <-channel
	fmt.Println("Bob received the second message from Alice and is now " +
		"decrypting it!")
	y = shamir.Calculate(x, bInv, prime)
	fmt.Println("Bob decrypted the following message from Alice: " +
		shamir.GlueMessage(y))
	stop <- 1
}
コード例 #6
0
ファイル: sockets_alice.go プロジェクト: jwoe/nokey-go
func send(channel chan []*big.Int, conn net.Conn) {
	_, err := conn.Write([]byte(shamir.GlueMessage(<-channel)))
	checkError(err)
}