diff --git a/main.go b/main.go index 117b111a..4de143cf 100644 --- a/main.go +++ b/main.go @@ -84,6 +84,7 @@ import ( _ "github.com/FloatTech/ZeroBot-Plugin/plugin/chrev" // 英文字符翻转 _ "github.com/FloatTech/ZeroBot-Plugin/plugin/coser" // 三次元小姐姐 _ "github.com/FloatTech/ZeroBot-Plugin/plugin/cpstory" // cp短打 + _ "github.com/FloatTech/ZeroBot-Plugin/plugin/crypter" // 奇怪语言加解密 _ "github.com/FloatTech/ZeroBot-Plugin/plugin/dailynews" // 今日早报 _ "github.com/FloatTech/ZeroBot-Plugin/plugin/danbooru" // DeepDanbooru二次元图标签识别 _ "github.com/FloatTech/ZeroBot-Plugin/plugin/diana" // 嘉心糖发病 diff --git a/plugin/crypter/fumo.go b/plugin/crypter/fumo.go new file mode 100644 index 00000000..e488bcb3 --- /dev/null +++ b/plugin/crypter/fumo.go @@ -0,0 +1,94 @@ +// Package crypter Fumo语 +package crypter + +import ( + "encoding/base64" + "fmt" + "regexp" + "strings" +) + +// Base64字符表 +const base64Chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" + +// Fumo语字符表 - 使用各种fumo变体来表示base64字符 +var fumoChars = []string{ + "fumo-", "Fumo-", "fUmo-", "fuMo-", "fumO-", "FUmo-", "FuMo-", "FumO-", + "fUMo-", "fUmO-", "fuMO-", "FUMo-", "FUmO-", "fUMO-", "FUMO-", "fumo.", + "Fumo.", "fUmo.", "fuMo.", "fumO.", "FUmo.", "FuMo.", "FumO.", "fUMo.", + "fUmO.", "fuMO.", "FUMo.", "FUmO.", "fUMO.", "FUMO.", "fumo,", "Fumo,", + "fUmo,", "fuMo,", "fumO,", "FUmo,", "FuMo,", "FumO,", "fUMo,", "fUmO,", + "fuMO,", "FUMo,", "FuMO,", "fUMO,", "FUMO,", "fumo+", "Fumo+", "fUmo+", + "fuMo+", "fumO+", "FUmo+", "FuMo+", "FumO+", "fUMo+", "fUmO+", "fuMO+", + "FUMo+", "FUmO+", "fUMO+", "FUMO+", "fumo|", "Fumo|", "fUmo|", "fuMo|", + "fumO|", "FUmo|", "FuMo|", "FumO|", "fUMo|", "fUmO|", "fuMO|", "fumo/", + "Fumo/", "fUmo/", +} + +//Base64 2 Fumo +// 创建编码映射表 +var encodeMap = make(map[byte]string) +// 创建解码映射表 +var decodeMap = make(map[string]byte) + +func init() { + for i := 0; i < 64 && i < len(fumoChars); i++ { + base64Char := base64Chars[i] + fumoChar := fumoChars[i] + + encodeMap[base64Char] = fumoChar + decodeMap[fumoChar] = base64Char + } +} + +//加密 +func encryptFumo(text string) string { + if text == "" { + return "请输入要加密的文本" + } + textBytes := []byte(text) + base64String := base64.StdEncoding.EncodeToString(textBytes) + base64Body := strings.TrimRight(base64String, "=") + paddingCount := len(base64String) - len(base64Body) + var fumoBody strings.Builder + for _, char := range base64Body { + if fumoChar, exists := encodeMap[byte(char)]; exists { + fumoBody.WriteString(fumoChar) + } else { + return fmt.Sprintf("Fumo加密失败: 未知字符 %c", char) + } + } + result := fumoBody.String() + strings.Repeat("=", paddingCount) + + return result +} + +//解密 +func decryptFumo(fumoText string) string { + if fumoText == "" { + return "请输入要解密的Fumo语密文" + } + fumoBody := strings.TrimRight(fumoText, "=") + paddingCount := len(fumoText) - len(fumoBody) + fumoPattern := regexp.MustCompile(`(\w+[-.,+|/])`) + fumoWords := fumoPattern.FindAllString(fumoBody, -1) + reconstructed := strings.Join(fumoWords, "") + if reconstructed != fumoBody { + return "Fumo解密失败: 包含无效的Fumo字符或格式错误" + } + var base64Body strings.Builder + for _, fumoWord := range fumoWords { + if base64Char, exists := decodeMap[fumoWord]; exists { + base64Body.WriteByte(base64Char) + } else { + return fmt.Sprintf("Fumo解密失败: 包含无效的Fumo字符 %s", fumoWord) + } + } + base64String := base64Body.String() + strings.Repeat("=", paddingCount) + decodedBytes, err := base64.StdEncoding.DecodeString(base64String) + if err != nil { + return fmt.Sprintf("Fumo解密失败: Base64解码错误 %v", err) + } + originalText := string(decodedBytes) + return originalText +} \ No newline at end of file diff --git a/plugin/crypter/handlers.go b/plugin/crypter/handlers.go new file mode 100644 index 00000000..cc949378 --- /dev/null +++ b/plugin/crypter/handlers.go @@ -0,0 +1,33 @@ +// Package crypter 处理函数 +package crypter + +import ( + zero "github.com/wdvxdr1123/ZeroBot" + "github.com/wdvxdr1123/ZeroBot/message" +) + +//hou +func houEncryptHandler(ctx *zero.Ctx) { + text := ctx.State["regex_matched"].([]string)[1] + result := encodeHou(text) + ctx.SendChain(message.Text(result)) +} + +func houDecryptHandler(ctx *zero.Ctx) { + text := ctx.State["regex_matched"].([]string)[1] + result := decodeHou(text) + ctx.SendChain(message.Text(result)) +} + +//fumo +func fumoEncryptHandler(ctx *zero.Ctx) { + text := ctx.State["regex_matched"].([]string)[1] + result := encryptFumo(text) + ctx.SendChain(message.Text(result)) +} + +func fumoDecryptHandler(ctx *zero.Ctx) { + text := ctx.State["regex_matched"].([]string)[1] + result := decryptFumo(text) + ctx.SendChain(message.Text(result)) +} \ No newline at end of file diff --git a/plugin/crypter/hou.go b/plugin/crypter/hou.go new file mode 100644 index 00000000..7bda968a --- /dev/null +++ b/plugin/crypter/hou.go @@ -0,0 +1,87 @@ +// Package crypter 齁语加解密 +package crypter + +import ( + "strings" +) + +// 齁语密码表 +var houCodebook = []string{ + "齁", "哦", "噢", "喔", "咕", "咿", "嗯", "啊", + "~", "哈", "!", "唔", "哼", "❤", "呃", "呼", +} +// 索引: 0 1 2 3 4 5 6 7 +// 8 9 10 11 12 13 14 15 + +// 创建映射表 +var houCodebookMap = make(map[string]int) + +// 初始化映射表 +func init() { + for idx, ch := range houCodebook { + houCodebookMap[ch] = idx + } +} + +func encodeHou(text string) string { + if text == "" { + return "请输入要加密的文本" + } + var encoded strings.Builder + textBytes := []byte(text) + for _, b := range textBytes { + high := (b >> 4) & 0x0F + low := b & 0x0F + encoded.WriteString(houCodebook[high]) + encoded.WriteString(houCodebook[low]) + } + + return encoded.String() +} + +func decodeHou(code string) string { + if code == "" { + return "请输入要解密的齁语密文" + } + + // 过滤出有效的齁语字符 + var validChars []string + for _, r := range code { + charStr := string(r) + if _, exists := houCodebookMap[charStr]; exists { + validChars = append(validChars, charStr) + } + } + + if len(validChars)%2 != 0 { + return "齁语密文长度错误,无法解密" + } + + // 解密过程 + var byteList []byte + for i := 0; i < len(validChars); i += 2 { + highIdx, highExists := houCodebookMap[validChars[i]] + lowIdx, lowExists := houCodebookMap[validChars[i+1]] + + if !highExists || !lowExists { + return "齁语密文包含无效字符" + } + + originalByte := byte((highIdx << 4) | lowIdx) + byteList = append(byteList, originalByte) + } + + result := string(byteList) + + if !isValidUTF8(result) { + return "齁语解密失败,结果不是有效的文本" + } + + return result +} + +// 检查字符串是否为有效的UTF-8编码 +func isValidUTF8(s string) bool { + // Go的string类型默认就是UTF-8,如果转换没有出错说明是有效的 + return len(s) > 0 || s == "" +} \ No newline at end of file diff --git a/plugin/crypter/main.go b/plugin/crypter/main.go new file mode 100644 index 00000000..e850a9b5 --- /dev/null +++ b/plugin/crypter/main.go @@ -0,0 +1,31 @@ +// Package crypter 奇怪语言加解密 +package crypter + +import ( + ctrl "github.com/FloatTech/zbpctrl" + "github.com/FloatTech/zbputils/control" + zero "github.com/wdvxdr1123/ZeroBot" +) + +func init() { + engine := control.Register("crypter", &ctrl.Options[*zero.Ctx]{ + DisableOnDefault: false, + Brief: "奇怪语言加解密", + Help: "多种语言加解密插件\n" + + "- 齁语加解密:\n" + + "- 齁语加密 [文本] 或 h加密 [文本]\n" + + "- 齁语解密 [密文] 或 h解密 [密文]\n\n" + + "- Fumo语加解密:\n" + + "- fumo加密 [文本]\n" + + "- fumo解密 [密文]\n\n", + PublicDataFolder: "Crypter", + }) + + //hou + engine.OnRegex(`^(?:齁语加密|h加密)\s*(.+)$`).SetBlock(true).Handle(houEncryptHandler) + engine.OnRegex(`^(?:齁语解密|h解密)\s*(.+)$`).SetBlock(true).Handle(houDecryptHandler) + + //Fumo + engine.OnRegex(`^fumo加密\s*(.+)$`).SetBlock(true).Handle(fumoEncryptHandler) + engine.OnRegex(`^fumo解密\s*(.+)$`).SetBlock(true).Handle(fumoDecryptHandler) +} \ No newline at end of file