Skip to content

Instantly share code, notes, and snippets.

@cstrouse
Last active December 30, 2015 23:39
Show Gist options
  • Save cstrouse/7902076 to your computer and use it in GitHub Desktop.
Save cstrouse/7902076 to your computer and use it in GitHub Desktop.
OverTheWire Vortex Level 0 Go solution
package main
import (
"bytes"
"encoding/binary"
"fmt"
"net"
)
func main() {
conn, err := net.Dial("tcp", "vortex.labs.overthewire.org:5842")
if err != nil {
fmt.Println("Unable to connect to host", err)
}
var sum uint32 = 0
for i := 0; i < 4; i++ {
data := make([]byte, 4)
conn.Read(data)
var x uint32 = 0
x = binary.LittleEndian.Uint32(data)
fmt.Println("Read in", x)
sum += x
}
fmt.Println("\nThe sum of read values is", sum)
buf := new(bytes.Buffer)
binary.Write(buf, binary.LittleEndian, sum)
conn.Write(buf.Bytes())
result := make([]byte, 64)
n, err := conn.Read(result[0:])
fmt.Println("\nRead", n, "bytes from socket\n\n", string(result))
conn.Close()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment