-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
main.go
50 lines (46 loc) · 805 Bytes
/
main.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
package main
import (
"bufio"
"fmt"
"log"
"net"
)
func handleConn(conn net.Conn) {
defer conn.Close()
scn := bufio.NewScanner(conn)
for scn.Scan() {
line := scn.Text()
bs := []byte(line)
result := make([]byte, len(bs))
for i, v := range bs {
if v <= 'z' && v >= 'a' {
result[i] = v + 13
if result[i] > 'z' {
result[i] -= 26
}
} else if v <= 'Z' && v >= 'A' {
result[i] = v + 13
if result[i] > 'Z' {
result[i] -= 26
}
} else {
result[i] = v
}
}
fmt.Fprintf(conn, "%s\n%s\n", result, bs)
}
}
func main() {
server, err := net.Listen("tcp", ":9000")
if err != nil {
log.Fatalln(err.Error())
}
defer server.Close()
for {
conn, err := server.Accept()
if err != nil {
log.Fatalln(err.Error())
}
go handleConn(conn)
}
}