-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathbadwords.go
More file actions
39 lines (34 loc) · 764 Bytes
/
Copy pathbadwords.go
File metadata and controls
39 lines (34 loc) · 764 Bytes
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
package couponcode
import (
"strings"
)
var (
// ROT13 ... because it doesn't need to be enigma
badwords = makeBadWords("SHPX PHAG JNAX JNAT CVFF PBPX FUVG GJNG GVGF SNEG URYY ZHSS QVPX XABO NEFR FUNT GBFF FYHG GHEQ FYNT PENC CBBC OHGG SRPX OBBO WVFZ WVMM CUNG")
)
func hasBadWord(code string) bool {
for _, badword := range badwords {
if strings.Contains(code, badword) {
return true
}
}
return false
}
func makeBadWords(badwords string) []string {
words := make([]rune, len(badwords))
for i, x := range badwords {
c := mapRune(x)
words[i] = c
}
return strings.Split(string(words), " ")
}
func mapRune(r rune) rune {
switch {
case 65 <= r && r <= 77:
return r + 13
case 78 <= r && r <= 90:
return r - 13
default:
return r
}
}