Last active
December 30, 2015 23:39
-
-
Save cstrouse/7902076 to your computer and use it in GitHub Desktop.
OverTheWire Vortex Level 0 Go solution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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