Created
February 27, 2017 02:11
-
-
Save gsilvis/d56b906c26e42125b17e55f7a9ff036e to your computer and use it in GitHub Desktop.
This file contains hidden or 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 ( | |
"encoding/binary" | |
"fmt" | |
"io" | |
"math" | |
"net" | |
) | |
func test_bomb(conn net.Conn, bomb byte) bool { | |
length := make([]byte, 2) | |
length[0] = 128 | |
length[1] = 0 | |
conn.Write(length) | |
for i := 0; i < 8192; i++ { | |
conn.Write([]byte{0x74}) | |
conn.Write([]byte{0x76}) | |
bits := math.Float64bits(math.Pi / 8192) | |
bytes := make([]byte, 8) | |
binary.LittleEndian.PutUint64(bytes, bits) | |
conn.Write(bytes) | |
conn.Write([]byte{0x74}) | |
conn.Write([]byte{bomb}) | |
} | |
result := make([]byte, 1) | |
io.ReadFull(conn, result) | |
if result[0] == 1 { | |
return false | |
} else { | |
return true | |
} | |
} | |
func main() { | |
socket, err := net.Dial("tcp", "localhost:8001") | |
if err != nil { | |
panic(err) | |
} | |
defer socket.Close() | |
guesses := make([]bool, 112) | |
for i := byte(0); i < 112; i++ { | |
fmt.Println(i) | |
guesses[i] = test_bomb(socket, i) | |
} | |
req := make([]byte, 2) | |
req[0] = 0 | |
req[1] = 0 | |
socket.Write(req) | |
guess := make([]byte, 14) | |
for i := 0; i < 14; i++ { | |
guess[i] = 0 | |
for j := 0; j < 8; j++ { | |
if guesses[8*i+j] { | |
guess[i] += 0x01 << uint16(7-j) | |
} | |
} | |
} | |
fmt.Println(guesses, guess) | |
socket.Write(guess) | |
response := make([]byte, 64) | |
io.ReadFull(socket, response) | |
fmt.Println(string(response)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment