diff --git a/README.md b/README.md index add8db9f..a9605d19 100644 --- a/README.md +++ b/README.md @@ -376,6 +376,20 @@ print("run[CQ:image,file="+j["img"]+"]") - [x] 百度下[xxx] + +
+ base64卦加解密 + + `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin/base64gua"` + + - [x] 六十四卦加密xxx + + - [x] 六十四卦解密xxx + + - [x] 六十四卦用yyy加密xxx + + - [x] 六十四卦用yyy解密xxx +
bilibili diff --git a/go.mod b/go.mod index c4c61d03..ae4b2f8d 100644 --- a/go.mod +++ b/go.mod @@ -20,6 +20,7 @@ require ( github.com/fumiama/gofastTEA v0.0.10 github.com/fumiama/gotracemoe v0.0.3 github.com/fumiama/sqlite3 v1.14.6 + github.com/fumiama/unibase2n v0.0.0-20221001124937-1eec9a152907 github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 github.com/jinzhu/gorm v1.9.16 github.com/jozsefsallai/gophersauce v1.0.1 diff --git a/go.sum b/go.sum index 0cb83c02..3d356f9a 100644 --- a/go.sum +++ b/go.sum @@ -58,6 +58,8 @@ github.com/fumiama/gotracemoe v0.0.3 h1:iI5EbE9A3UUbfukG6+/soYPjp1S31eCNYf4tw7s6 github.com/fumiama/gotracemoe v0.0.3/go.mod h1:tyqahdUzHf0bQIAVY/GYmDWvYYe5ik1ZbhnGYh+zl40= github.com/fumiama/sqlite3 v1.14.6 h1:+e+iygyiDXQJVi7xeXIviBvR7hAc5y20WA9hRwfKn10= github.com/fumiama/sqlite3 v1.14.6/go.mod h1:Xx9a2/OtHuy9pBjow0N+bE/RhNeZ7zZz5xh25vqbA5A= +github.com/fumiama/unibase2n v0.0.0-20221001124937-1eec9a152907 h1:x+wRdSK0Hx9X+pBxB7jN/hnir55Rbh3KJ9eiGzIb4GY= +github.com/fumiama/unibase2n v0.0.0-20221001124937-1eec9a152907/go.mod h1:lEaZsT4FRSqcjnQ5q8y+mkenkzR/r1D3BJmfdp0vqDg= github.com/gabriel-vasile/mimetype v1.0.4 h1:uBejfH8l3/2f+5vjl1e4xIaSyNEhRBZ5N/ij7ohpNd8= github.com/gabriel-vasile/mimetype v1.0.4/go.mod h1:6CDPel/o/3/s4+bp6kIbsWATq8pmgOisOPG40CJa6To= github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg= diff --git a/main.go b/main.go index 4e18c620..e7977393 100644 --- a/main.go +++ b/main.go @@ -63,6 +63,7 @@ import ( _ "github.com/FloatTech/ZeroBot-Plugin/plugin/aiwife" // 随机老婆 _ "github.com/FloatTech/ZeroBot-Plugin/plugin/b14" // base16384加解密 _ "github.com/FloatTech/ZeroBot-Plugin/plugin/baidu" // 百度一下 + _ "github.com/FloatTech/ZeroBot-Plugin/plugin/base64gua" // base64卦加解密 _ "github.com/FloatTech/ZeroBot-Plugin/plugin/bilibili" // b站相关 _ "github.com/FloatTech/ZeroBot-Plugin/plugin/book_review" // 哀伤雪刃吧推书记录 _ "github.com/FloatTech/ZeroBot-Plugin/plugin/cangtoushi" // 藏头诗 @@ -147,7 +148,7 @@ import ( _ "github.com/FloatTech/ZeroBot-Plugin/plugin/ai_reply" // 人工智能回复 - _ "github.com/FloatTech/ZeroBot-Plugin/plugin/breakrepeat" // 打断复读 + _ "github.com/FloatTech/ZeroBot-Plugin/plugin/breakrepeat" // 打断复读 // ^^^^ // // ^^^^^^^^^^^^^^ // diff --git a/plugin/base64gua/main.go b/plugin/base64gua/main.go new file mode 100644 index 00000000..fc510194 --- /dev/null +++ b/plugin/base64gua/main.go @@ -0,0 +1,76 @@ +// Package base64gua base64卦 与 tea 加解密 +package base64gua + +import ( + "unsafe" + + ctrl "github.com/FloatTech/zbpctrl" + "github.com/FloatTech/zbputils/control" + tea "github.com/fumiama/gofastTEA" + "github.com/fumiama/unibase2n" + zero "github.com/wdvxdr1123/ZeroBot" + "github.com/wdvxdr1123/ZeroBot/message" + "github.com/wdvxdr1123/ZeroBot/utils/helper" +) + +func init() { + en := control.Register("base64gua", &ctrl.Options[*zero.Ctx]{ + DisableOnDefault: false, + Help: "base64gua加解密\n" + + "- 六十四卦加密xxx\n- 六十四卦解密xxx\n- 六十四卦用yyy加密xxx\n- 六十四卦用yyy解密xxx", + }) + en.OnRegex(`^六十四卦加密\s*(.+)$`).SetBlock(true). + Handle(func(ctx *zero.Ctx) { + str := ctx.State["regex_matched"].([]string)[1] + es := unibase2n.Base64Gua.EncodeString(str) + if es != "" { + ctx.SendChain(message.Text(es)) + } else { + ctx.SendChain(message.Text("加密失败!")) + } + }) + en.OnRegex(`^六十四卦解密\s*([䷀-䷿]+[☰☱]?)$`).SetBlock(true). + Handle(func(ctx *zero.Ctx) { + str := ctx.State["regex_matched"].([]string)[1] + es := unibase2n.Base64Gua.DecodeString(str) + if es != "" { + ctx.SendChain(message.Text(es)) + } else { + ctx.SendChain(message.Text("解密失败!")) + } + }) + en.OnRegex(`^六十四卦用(.+)加密\s*(.+)$`).SetBlock(true). + Handle(func(ctx *zero.Ctx) { + key, str := ctx.State["regex_matched"].([]string)[1], ctx.State["regex_matched"].([]string)[2] + t := getea(key) + es, err := unibase2n.UTF16BE2UTF8(unibase2n.Base64Gua.Encode(t.Encrypt(helper.StringToBytes(str)))) + if err == nil { + ctx.SendChain(message.Text(helper.BytesToString(es))) + } else { + ctx.SendChain(message.Text("加密失败!")) + } + }) + en.OnRegex(`^六十四卦用(.+)解密\s*([一-踀]+[㴁-㴆]?)$`).SetBlock(true). + Handle(func(ctx *zero.Ctx) { + key, str := ctx.State["regex_matched"].([]string)[1], ctx.State["regex_matched"].([]string)[2] + t := getea(key) + es, err := unibase2n.UTF82UTF16BE(helper.StringToBytes(str)) + if err == nil { + ctx.SendChain(message.Text(helper.BytesToString(t.Decrypt(unibase2n.Base64Gua.Decode(es))))) + } else { + ctx.SendChain(message.Text("解密失败!")) + } + }) +} + +func getea(key string) tea.TEA { + kr := []rune(key) + if len(kr) > 4 { + kr = kr[:4] + } else { + for len(kr) < 4 { + kr = append(kr, rune(4-len(kr))) + } + } + return *(*tea.TEA)(*(*unsafe.Pointer)(unsafe.Pointer(&kr))) +}