Skip to content

Commit 1e7b2d3

Browse files
authored
feat: 添加插件 crypter (FloatTech#1191)
1 parent 20d49cc commit 1e7b2d3

File tree

5 files changed

+246
-0
lines changed

5 files changed

+246
-0
lines changed

main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ import (
8484
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/chrev" // 英文字符翻转
8585
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/coser" // 三次元小姐姐
8686
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/cpstory" // cp短打
87+
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/crypter" // 奇怪语言加解密
8788
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/dailynews" // 今日早报
8889
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/danbooru" // DeepDanbooru二次元图标签识别
8990
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/diana" // 嘉心糖发病

plugin/crypter/fumo.go

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
// Package crypter Fumo语
2+
package crypter
3+
4+
import (
5+
"encoding/base64"
6+
"fmt"
7+
"regexp"
8+
"strings"
9+
)
10+
11+
// Base64字符表
12+
const base64Chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
13+
14+
// Fumo语字符表 - 使用各种fumo变体来表示base64字符
15+
var fumoChars = []string{
16+
"fumo-", "Fumo-", "fUmo-", "fuMo-", "fumO-", "FUmo-", "FuMo-", "FumO-",
17+
"fUMo-", "fUmO-", "fuMO-", "FUMo-", "FUmO-", "fUMO-", "FUMO-", "fumo.",
18+
"Fumo.", "fUmo.", "fuMo.", "fumO.", "FUmo.", "FuMo.", "FumO.", "fUMo.",
19+
"fUmO.", "fuMO.", "FUMo.", "FUmO.", "fUMO.", "FUMO.", "fumo,", "Fumo,",
20+
"fUmo,", "fuMo,", "fumO,", "FUmo,", "FuMo,", "FumO,", "fUMo,", "fUmO,",
21+
"fuMO,", "FUMo,", "FuMO,", "fUMO,", "FUMO,", "fumo+", "Fumo+", "fUmo+",
22+
"fuMo+", "fumO+", "FUmo+", "FuMo+", "FumO+", "fUMo+", "fUmO+", "fuMO+",
23+
"FUMo+", "FUmO+", "fUMO+", "FUMO+", "fumo|", "Fumo|", "fUmo|", "fuMo|",
24+
"fumO|", "FUmo|", "FuMo|", "FumO|", "fUMo|", "fUmO|", "fuMO|", "fumo/",
25+
"Fumo/", "fUmo/",
26+
}
27+
28+
//Base64 2 Fumo
29+
// 创建编码映射表
30+
var encodeMap = make(map[byte]string)
31+
// 创建解码映射表
32+
var decodeMap = make(map[string]byte)
33+
34+
func init() {
35+
for i := 0; i < 64 && i < len(fumoChars); i++ {
36+
base64Char := base64Chars[i]
37+
fumoChar := fumoChars[i]
38+
39+
encodeMap[base64Char] = fumoChar
40+
decodeMap[fumoChar] = base64Char
41+
}
42+
}
43+
44+
//加密
45+
func encryptFumo(text string) string {
46+
if text == "" {
47+
return "请输入要加密的文本"
48+
}
49+
textBytes := []byte(text)
50+
base64String := base64.StdEncoding.EncodeToString(textBytes)
51+
base64Body := strings.TrimRight(base64String, "=")
52+
paddingCount := len(base64String) - len(base64Body)
53+
var fumoBody strings.Builder
54+
for _, char := range base64Body {
55+
if fumoChar, exists := encodeMap[byte(char)]; exists {
56+
fumoBody.WriteString(fumoChar)
57+
} else {
58+
return fmt.Sprintf("Fumo加密失败: 未知字符 %c", char)
59+
}
60+
}
61+
result := fumoBody.String() + strings.Repeat("=", paddingCount)
62+
63+
return result
64+
}
65+
66+
//解密
67+
func decryptFumo(fumoText string) string {
68+
if fumoText == "" {
69+
return "请输入要解密的Fumo语密文"
70+
}
71+
fumoBody := strings.TrimRight(fumoText, "=")
72+
paddingCount := len(fumoText) - len(fumoBody)
73+
fumoPattern := regexp.MustCompile(`(\w+[-.,+|/])`)
74+
fumoWords := fumoPattern.FindAllString(fumoBody, -1)
75+
reconstructed := strings.Join(fumoWords, "")
76+
if reconstructed != fumoBody {
77+
return "Fumo解密失败: 包含无效的Fumo字符或格式错误"
78+
}
79+
var base64Body strings.Builder
80+
for _, fumoWord := range fumoWords {
81+
if base64Char, exists := decodeMap[fumoWord]; exists {
82+
base64Body.WriteByte(base64Char)
83+
} else {
84+
return fmt.Sprintf("Fumo解密失败: 包含无效的Fumo字符 %s", fumoWord)
85+
}
86+
}
87+
base64String := base64Body.String() + strings.Repeat("=", paddingCount)
88+
decodedBytes, err := base64.StdEncoding.DecodeString(base64String)
89+
if err != nil {
90+
return fmt.Sprintf("Fumo解密失败: Base64解码错误 %v", err)
91+
}
92+
originalText := string(decodedBytes)
93+
return originalText
94+
}

plugin/crypter/handlers.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Package crypter 处理函数
2+
package crypter
3+
4+
import (
5+
zero "github.com/wdvxdr1123/ZeroBot"
6+
"github.com/wdvxdr1123/ZeroBot/message"
7+
)
8+
9+
//hou
10+
func houEncryptHandler(ctx *zero.Ctx) {
11+
text := ctx.State["regex_matched"].([]string)[1]
12+
result := encodeHou(text)
13+
ctx.SendChain(message.Text(result))
14+
}
15+
16+
func houDecryptHandler(ctx *zero.Ctx) {
17+
text := ctx.State["regex_matched"].([]string)[1]
18+
result := decodeHou(text)
19+
ctx.SendChain(message.Text(result))
20+
}
21+
22+
//fumo
23+
func fumoEncryptHandler(ctx *zero.Ctx) {
24+
text := ctx.State["regex_matched"].([]string)[1]
25+
result := encryptFumo(text)
26+
ctx.SendChain(message.Text(result))
27+
}
28+
29+
func fumoDecryptHandler(ctx *zero.Ctx) {
30+
text := ctx.State["regex_matched"].([]string)[1]
31+
result := decryptFumo(text)
32+
ctx.SendChain(message.Text(result))
33+
}

plugin/crypter/hou.go

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// Package crypter 齁语加解密
2+
package crypter
3+
4+
import (
5+
"strings"
6+
)
7+
8+
// 齁语密码表
9+
var houCodebook = []string{
10+
"齁", "哦", "噢", "喔", "咕", "咿", "嗯", "啊",
11+
"~", "哈", "!", "唔", "哼", "❤", "呃", "呼",
12+
}
13+
// 索引: 0 1 2 3 4 5 6 7
14+
// 8 9 10 11 12 13 14 15
15+
16+
// 创建映射表
17+
var houCodebookMap = make(map[string]int)
18+
19+
// 初始化映射表
20+
func init() {
21+
for idx, ch := range houCodebook {
22+
houCodebookMap[ch] = idx
23+
}
24+
}
25+
26+
func encodeHou(text string) string {
27+
if text == "" {
28+
return "请输入要加密的文本"
29+
}
30+
var encoded strings.Builder
31+
textBytes := []byte(text)
32+
for _, b := range textBytes {
33+
high := (b >> 4) & 0x0F
34+
low := b & 0x0F
35+
encoded.WriteString(houCodebook[high])
36+
encoded.WriteString(houCodebook[low])
37+
}
38+
39+
return encoded.String()
40+
}
41+
42+
func decodeHou(code string) string {
43+
if code == "" {
44+
return "请输入要解密的齁语密文"
45+
}
46+
47+
// 过滤出有效的齁语字符
48+
var validChars []string
49+
for _, r := range code {
50+
charStr := string(r)
51+
if _, exists := houCodebookMap[charStr]; exists {
52+
validChars = append(validChars, charStr)
53+
}
54+
}
55+
56+
if len(validChars)%2 != 0 {
57+
return "齁语密文长度错误,无法解密"
58+
}
59+
60+
// 解密过程
61+
var byteList []byte
62+
for i := 0; i < len(validChars); i += 2 {
63+
highIdx, highExists := houCodebookMap[validChars[i]]
64+
lowIdx, lowExists := houCodebookMap[validChars[i+1]]
65+
66+
if !highExists || !lowExists {
67+
return "齁语密文包含无效字符"
68+
}
69+
70+
originalByte := byte((highIdx << 4) | lowIdx)
71+
byteList = append(byteList, originalByte)
72+
}
73+
74+
result := string(byteList)
75+
76+
if !isValidUTF8(result) {
77+
return "齁语解密失败,结果不是有效的文本"
78+
}
79+
80+
return result
81+
}
82+
83+
// 检查字符串是否为有效的UTF-8编码
84+
func isValidUTF8(s string) bool {
85+
// Go的string类型默认就是UTF-8,如果转换没有出错说明是有效的
86+
return len(s) > 0 || s == ""
87+
}

plugin/crypter/main.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Package crypter 奇怪语言加解密
2+
package crypter
3+
4+
import (
5+
ctrl "github.com/FloatTech/zbpctrl"
6+
"github.com/FloatTech/zbputils/control"
7+
zero "github.com/wdvxdr1123/ZeroBot"
8+
)
9+
10+
func init() {
11+
engine := control.Register("crypter", &ctrl.Options[*zero.Ctx]{
12+
DisableOnDefault: false,
13+
Brief: "奇怪语言加解密",
14+
Help: "多种语言加解密插件\n" +
15+
"- 齁语加解密:\n" +
16+
"- 齁语加密 [文本] 或 h加密 [文本]\n" +
17+
"- 齁语解密 [密文] 或 h解密 [密文]\n\n" +
18+
"- Fumo语加解密:\n" +
19+
"- fumo加密 [文本]\n" +
20+
"- fumo解密 [密文]\n\n",
21+
PublicDataFolder: "Crypter",
22+
})
23+
24+
//hou
25+
engine.OnRegex(`^(?:齁语加密|h加密)\s*(.+)$`).SetBlock(true).Handle(houEncryptHandler)
26+
engine.OnRegex(`^(?:齁语解密|h解密)\s*(.+)$`).SetBlock(true).Handle(houDecryptHandler)
27+
28+
//Fumo
29+
engine.OnRegex(`^fumo加密\s*(.+)$`).SetBlock(true).Handle(fumoEncryptHandler)
30+
engine.OnRegex(`^fumo解密\s*(.+)$`).SetBlock(true).Handle(fumoDecryptHandler)
31+
}

0 commit comments

Comments
 (0)