-
Notifications
You must be signed in to change notification settings - Fork 0
/
29.go
47 lines (41 loc) · 1.26 KB
/
29.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package main
import (
"fmt"
"net/http"
"io/ioutil"
"strings"
"bytes"
"compress/bzip2"
)
func main(){
page, _ := getbody("guido.html")
lines := strings.Split(strings.ReplaceAll(string(page), "\r\n", "\n"), "\n")
lens := []uint8{}
for i, line := range lines {
// parsing empty lines
if strings.TrimSpace(line) == "" {
if len(line) > 255 { panic("tofu/") }
fmt.Println(i, len(line))
lens = append(lens, uint8(len(line)))
}
}
buff := bytes.NewBuffer(lens)
reader := bzip2.NewReader(buff)
res, err := ioutil.ReadAll(reader)
fmt.Println(yell("err/readall"), err)
fmt.Println("res/", string(res))
}
func getbody(sub string) ( []uint8, error ) {
URL := "http://www.pythonchallenge.com/pc/ring/"
conn := & http.Client{}
req, _ := http.NewRequest("GET", URL + sub, nil)
req.SetBasicAuth( "repeat", "switch" )
resp, _ := conn.Do(req)
defer resp.Body.Close()
data, _ := ioutil.ReadAll(resp.Body)
fmt.Println(string(data), yell("\bbody ends/"))
return data, nil
}
const Yell, Cyan, Rest string = "\033[33m", "\033[36m", "\033[0m"
func yell(s string) string { return Yell + s + Rest }
func cyan(s string) string { return Cyan + s + Rest }