-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.go
78 lines (66 loc) · 1.58 KB
/
client.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
package main
import (
"bufio"
"fmt"
"log"
"math"
"net"
"os"
"strconv"
"strings"
"time"
)
func main() {
conn, err := net.Dial("tcp", ":8000")
if nil != err {
log.Println(err)
}
go func() {
data := make([]byte, 4096)
for {
n, err := conn.Read(data)
if err != nil {
log.Println(err)
return
}
fmt.Println("Server send : " + string(data[:n]))
time.Sleep(time.Duration(3) * time.Second)
}
}()
var username string;
fmt.Print("Enter username: ");
fmt.Scanln(&username);
userId := RobinFingerprint(username);
for {
var s string
scanner := bufio.NewScanner(os.Stdin);
scanner.Scan();
s = scanner.Text();
// Header
contentLenght := len(s);
t := time.Now();
time_format := t.Format(time.RFC3339);
header := strconv.Itoa(userId) + "Content-Length:" + strconv.Itoa(contentLenght) + "," + "language:en," + "date-time:" + time_format + "\n\n";
payload := s;
packet := header + payload;
bin := StringToBin(packet);
bin = "01" + bin
conn.Write([]byte(bin))
time.Sleep(time.Duration(3) * time.Second)
}
}
func RobinFingerprint(username string) int{
username = strings.ToLower(username);
var sum float64 = 0;
for i := 0; i < len(username); i++ {
sum += float64((float64(username[i]) * math.Pow(16, float64(i))));
}
return int(math.Mod(sum, 64)) ;
}
func StringToBin(s string) string {
res := ""
for _, c := range s {
res = fmt.Sprintf("%s%.8b", res, c)
}
return res
}