-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-pft.go
111 lines (99 loc) · 1.87 KB
/
test-pft.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package main
import (
"fmt"
"io/ioutil"
"math/rand"
"net/http"
"os/exec"
"strconv"
"strings"
"sync"
"time"
)
var wg sync.WaitGroup
func rot13(r rune) rune {
switch {
case r >= 'A' && r <= 'Z':
return 'A' + (r-'A'+13)%26
case r >= 'a' && r <= 'z':
return 'a' + (r-'a'+13)%26
}
return r
}
func main() {
rand.Seed(time.Now().UnixNano())
results := make(chan result)
workers := 40
requests := 3000000000
for i := 1; i <= workers; i++ {
wg.Add(1)
go worker(i, requests, results)
}
go func() {
var warn string
for k := range results {
if k.err != nil {
fmt.Println(k.err)
continue
}
warn = "MATCH"
if k.oracle > k.beep {
warn = "LESSER"
}
if k.oracle < k.beep {
warn = "GREATER"
}
fmt.Println(k.question, "oracle =", k.oracle, "beep =", k.beep, warn)
}
}()
wg.Wait()
}
type result struct {
question uint64
oracle uint64
beep uint64
err error
}
func worker(id int, qty int, results chan<- result) {
defer wg.Done()
var r result
oracle := fmt.Sprintf(strings.Map(rot13, "cresrpg-ovgf.ovagv.pbz"))
for i := 0; i < qty; i++ {
r.question = rand.Uint64()
request := fmt.Sprintf("https://%s/?a=0&b=%d", oracle, r.question)
resp, err := http.Get(request)
if err != nil {
r.err = err
results <- r
continue
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
r.err = err
results <- r
continue
}
r.oracle, err = strconv.ParseUint(string(body), 10, 64)
if err != nil {
r.err = err
results <- r
continue
}
qry := fmt.Sprintf("%d", r.question)
out, err := exec.Command("./pft", "0", qry).Output()
if err != nil {
r.err = err
results <- r
continue
}
answer := strings.TrimSpace(string(out))
r.beep, err = strconv.ParseUint(answer, 10, 64)
if err != nil {
r.err = err
results <- r
continue
}
results <- r
}
}