-
Notifications
You must be signed in to change notification settings - Fork 32
/
rot.go
55 lines (43 loc) · 1019 Bytes
/
rot.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
package processors
import "strings"
// ROT13Encode convert string to ROT13 encoding.
type ROT13Encode struct{}
func (p ROT13Encode) Name() string {
return "rot13-encode"
}
func (p ROT13Encode) Alias() []string {
return []string{"rot13", "rot13-enc"}
}
func (p ROT13Encode) Transform(data []byte, _ ...Flag) (string, error) {
return strings.Map(rot13, string(data)), nil
}
func (p ROT13Encode) Flags() []Flag {
return nil
}
func (p ROT13Encode) Title() string {
return "ROT13 Encode"
}
func (p ROT13Encode) Description() string {
return "Encode your text to ROT13"
}
func (p ROT13Encode) FilterValue() string {
return p.Title()
}
// rot13 private helper function for converting rune into rot13.
func rot13(r rune) rune {
if r >= 'a' && r <= 'z' {
// Rotate lowercase letters 13 places.
if r >= 'm' {
return r - 13
}
return r + 13
} else if r >= 'A' && r <= 'Z' {
// Rotate uppercase letters 13 places.
if r >= 'M' {
return r - 13
}
return r + 13
}
// Do nothing.
return r
}