增加了机器人加解密功能,基于维吉尼亚算法

This commit is contained in:
95478 2024-09-26 22:46:58 +08:00
parent 6b55ac4da0
commit 2a82d732e5
12 changed files with 215 additions and 28 deletions

Binary file not shown.

View File

@ -1,38 +1,38 @@
[
{
"host": "111.30.169.83",
"port": 443
},
{
"host": "msfwifi.3g.qq.com",
"port": 8080
},
{
"host": "111.30.182.254",
"port": 443
"host": "116.130.229.191",
"port": 80
},
{
"host": "36.155.207.230",
"port": 443
"host": "182.50.15.44",
"port": 80
},
{
"host": "120.232.31.239",
"host": "123.125.0.195",
"port": 80
},
{
"host": "220.194.118.236",
"port": 80
},
{
"host": "182.50.8.188",
"port": 8080
},
{
"host": "120.241.130.195",
"host": "157.148.55.96",
"port": 443
},
{
"host": "157.255.5.104",
"port": 8080
},
{
"host": "153.3.244.48",
"port": 14000
},
{
"host": "36.155.163.25",
"port": 80
},
{
"host": "39.156.126.178",
"port": 80
},
{
"host": "36.155.163.117",
"port": 8080
}
]

View File

@ -1,2 +1,2 @@
h<EFBFBD>×­ <09>äÉu¯+]uµSfJv°v)POßtϺRë¼ÈB¥fž²,y¦*ç ú.¦Î<C2A6> ÊÑQtÒq-Úì†ñùé;y…ÿÚåJ¤ëxçLË"&ª¸Kôdì™<C3AC>J8Ò7ÏmdKjNc8WfFjkszCzNïüЄûÿÿÿÿ<10>? øÐƒÉ<10>?ï¾ÀßPõòþßÿÿÿÿÿ»" D­»" ¤¶‚§»" øÒϰ»"H•ÿÿÿÿÿ»
h'”ºLíe¯ˆíÍ"qj½Ä€¡Ë<C2A1>x§å$/žËVà9zQ6ÚZ¯ÌÓ³Jë><3E>2ïÖ<C3AF>*90;å©Ùƒ¼Õ±DC#Ðj ÐÙ2„À[eO¶& )ÉQŒ‡øš§)ë² dmtWkf9fgTW67wH4 Ú™„Ã<10>?ô„’Ïúÿÿÿÿ<10>? ð¬™ßþÿÿÿÿP <08>©»" ýΠ“»" ™‡¼Ù»"Ü…Û“ýÿÿÿÿ»" ™Ë”û»

View File

@ -15,6 +15,7 @@ public class listController {
return "今日好友消息:[" + HandleMessageListener.friendMessageCount + "]条<br>" +
"今日群聊1消息[" + HandleMessageListener.group1MessageCount + "]条<br>" +
"今日群聊2消息[" + HandleMessageListener.group2MessageCount + "]条<br>" +
"牢豆年糕汤消息:[" + HandleMessageListener.group3MessageCount + "]条<br>" +
"今日收到的群聊临时会话消息:[" + HandleMessageListener.groupTempMessageCount + "]条<br><br>" +
"今日群聊1违禁消息[" + RecallMessageListener.group1InvalidCount + "]条<br>" +
"今日群聊2违禁消息[" + RecallMessageListener.group2InvalidCount + "]条<br>" +

View File

@ -11,6 +11,7 @@ public class HandleMessageListener {
public static int friendMessageCount = 0;
public static int group1MessageCount = 0;
public static int group2MessageCount = 0;
public static int group3MessageCount = 0;
public static int groupTempMessageCount = 0;
@ -38,6 +39,12 @@ public class HandleMessageListener {
group2MessageCount++;
}
@RobotListenerHandler(contactId = 850111709)
public void handleGroupLAODOUMessage(GroupMessageEvent event) {
handleGroupMessage(event);
group3MessageCount++;
}
@RobotListenerHandler
public void handleGroupTempMessage(GroupTempMessageEvent event) {
String message = event.getMessage().contentToString();

View File

@ -22,7 +22,7 @@ public class RecallMessageListener extends MessageListener {
public static List<Long> group2InvalidMember = new ArrayList<Long>();
public RecallMessageListener() {
super(List.of("原神", "OP"), true);//自定义违禁词
super(List.of("原神"), true);//自定义违禁词
}
public int recall(GroupMessageEvent event, int groupInvalidCount, Map<Long, Integer> groupMemberInvalidedCountList, List<Long> groupInvalidMember) throws InterruptedException {//当有人发违禁词自动撤回并禁言一分钟

View File

@ -27,7 +27,7 @@ public class sendByConsoleListener extends MessageListener {
System.out.println("机器人发送:" + str);
}
@RobotListenerHandler(contactId = {518909220, 1033597003}, concurrency = true)//当有人消息中带有呼叫bot可以从控制台输入一条消息发送
@RobotListenerHandler(concurrency = true)//当有人消息中带有呼叫管理可以从控制台输入一条消息发送
public void sendMessageToGroup(GroupMessageEvent event) {
String message = event.getMessage().contentToString();
if (this.invalidText(message)) {
@ -35,7 +35,8 @@ public class sendByConsoleListener extends MessageListener {
String str = input.nextLine();
MessageChain chain = new MessageChainBuilder()
.append(new At(event.getSender().getId()))
.append(" " + str)
.append(" ")
.append(str)
.build();
event.getGroup().sendMessage(chain);
System.out.println("机器人发送:" + chain);

View File

@ -0,0 +1,34 @@
package com.mtz.qqbot.Listener;
import com.mtz.qqbot.Service.vService;
import net.itbaima.robot.event.RobotListener;
import net.itbaima.robot.event.RobotListenerHandler;
import net.itbaima.robot.listener.MessageListener;
import net.mamoe.mirai.event.events.GroupMessageEvent;
import net.mamoe.mirai.message.data.At;
import net.mamoe.mirai.message.data.MessageChain;
import net.mamoe.mirai.message.data.MessageChainBuilder;
import java.util.List;
@RobotListener
public class vDecryptListener extends MessageListener {
public vDecryptListener() {
super(List.of("解密"), true);
}
@RobotListenerHandler
public void decrypt(GroupMessageEvent event) {
String message = event.getMessage().contentToString();
if (this.invalidText(message)) {
String[] originMessage = message.split(" ");
String plaintext = String.valueOf(vService.Decrypt(originMessage));
MessageChain chain = new MessageChainBuilder()
.append(new At(event.getSender().getId()))
.append(" ")
.append(plaintext)
.build();
event.getGroup().sendMessage(chain);
}
}
}

View File

@ -0,0 +1,35 @@
package com.mtz.qqbot.Listener;
import com.mtz.qqbot.Service.vService;
import net.itbaima.robot.event.RobotListener;
import net.itbaima.robot.event.RobotListenerHandler;
import net.itbaima.robot.listener.MessageListener;
import net.mamoe.mirai.event.events.GroupMessageEvent;
import net.mamoe.mirai.message.data.At;
import net.mamoe.mirai.message.data.MessageChain;
import net.mamoe.mirai.message.data.MessageChainBuilder;
import java.io.IOException;
import java.util.List;
@RobotListener
public class vEncryptListener extends MessageListener {
public vEncryptListener() {
super(List.of("加密"), true);
}
@RobotListenerHandler
public void encrypt(GroupMessageEvent event) throws IOException {
String message = event.getMessage().contentToString();
if (this.invalidText(message)) {
String[] originMessage = message.split(" ");
String ciphertext = String.valueOf(vService.Encrypt(originMessage));
MessageChain chain = new MessageChainBuilder()
.append(new At(event.getSender().getId()))
.append(" ")
.append(ciphertext)
.build();
event.getGroup().sendMessage(chain);
}
}
}

View File

@ -0,0 +1,68 @@
package com.mtz.qqbot.Service;
import com.mtz.qqbot.Tool.vTools;
import java.io.IOException;
import java.util.ArrayList;
import static com.mtz.qqbot.Tool.vTools.alphabet;
public class vService {
public static StringBuilder Encrypt(String[] originMessage) throws IOException {
//加密
String passwd = originMessage[2];
char[] passwd1 = passwd.toCharArray();
ArrayList<Integer> passwdList = vTools.Transform(passwd1);
//System.out.println("密钥转换为密钥数字串为:" + passwdList);
String plaintext = originMessage[1];
char[] plaintext1 = plaintext.toCharArray();
ArrayList<Integer> plaintextList = vTools.Transform(plaintext1);
//System.out.println("明文转换为明文数字串为" + plaintextList);
vTools.Longer(passwdList, plaintextList);
//System.out.println("增加后的密钥数字串:" + passwdList);
//输出密文
StringBuilder ciphertext = new StringBuilder();
for (int i = 0; i < plaintextList.size(); i++) {
if ((plaintextList.get(i) + passwdList.get(i)) >= alphabet.length) {
plaintextList.set(i, (passwdList.get(i) + plaintextList.get(i) - alphabet.length));
} else {
plaintextList.set(i, (passwdList.get(i) + plaintextList.get(i)));
}
ciphertext.append(alphabet[plaintextList.get(i)]);
}
return ciphertext;
}
public static StringBuilder Decrypt(String[] originMessage) {
//解密
String passwd = originMessage[2];
char[] passwd1 = passwd.toCharArray();
ArrayList<Integer> passwdList = vTools.Transform(passwd1);
String ciphertext = originMessage[1];
char[] ciphertext1 = ciphertext.toCharArray();
ArrayList<Integer> ciphertextList = vTools.Transform(ciphertext1);
//System.out.println("密文转换为密文数字串为" + ciphertextList);
vTools.Longer(passwdList, ciphertextList);
//System.out.println("增加后的密钥数字串:" + passwdList);
//输出明文
StringBuilder plaintext = new StringBuilder();
for (int i = 0; i < ciphertextList.size(); i++) {
if ((ciphertextList.get(i) - passwdList.get(i)) < 0) {
ciphertextList.set(i, ciphertextList.get(i) - passwdList.get(i) + alphabet.length);
} else {
ciphertextList.set(i, ciphertextList.get(i) - passwdList.get(i));
}
plaintext.append(alphabet[ciphertextList.get(i)]);
}
return plaintext;
}
}

View File

@ -0,0 +1,41 @@
package com.mtz.qqbot.Tool;
import java.util.ArrayList;
import java.util.Scanner;
public class vTools {
//字符表
public static char[] alphabet = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', '/', '.', '-', '_', '?', '=', '&', '%'};
public static ArrayList<Integer> Transform(char[] text) {
ArrayList<Integer> list = new ArrayList<>();
for (char c : text) {
for (int j = 0; j < alphabet.length; j++) {
if (c == alphabet[j]) {
list.add(j);
}
}
}
return list;
}
public static void Longer(ArrayList<Integer> passwdList, ArrayList<Integer> list) {
int i = 0;
while (passwdList.size() < list.size()) {
passwdList.add(passwdList.get(i));
i++;
}
}
public static int Input() {
//防止玩家输入其他字符的输入数字方法
Scanner scanner = new Scanner(System.in);
if (scanner.hasNextInt()) {
return scanner.nextInt();
} else {
System.out.println("请输入数字!");
System.out.print("请输入:");
return Input();
}
}
}

View File

@ -6,13 +6,13 @@ itbaima:
password: mtzmtq2002
signer:
version: 8.9.71
version: 8.9.63
url: http://localhost:8888
type: fuqiuluo
authorization-key: 114514
data:
contact-cache: true
contact-cache: false
work-dir: robot-data
cache-dir: cache