|
发表于 2022-1-23 22:53:17
来自手机
|
显示全部楼层
import java.util.*;
import java.util.regex.*;
//import java.util.ArrayList;
//import java.util.Arrays;
import java.lang.*;
AddItem("开启/关闭加密","Change",PluginID);
AddItem("开启/关闭解密","unlock",PluginID);
Toast("文字加密java已加载,需要取消加载其它的小尾巴java才能正常使用!");
public void Change(String qun,String qq,int type)
{
String num=qun;
if(type!=1)num=qq;
if(("1"+type).equals(getString(num,"加密")))
{
putString(num, "加密", null);
Toast("本聊天加密已关闭");
}
else{
putString(num,"加密","1"+type);
Toast("本聊天加密已开启");
}
}
public void unlock(String qun,String qq,int type)
{
String num=qun;
if(type!=1)num=qq;
if(("1"+type).equals(getString(num,"解密")))
{
putString(num, "解密", null);
Toast("本聊天解密已关闭");
}
else{
putString(num,"解密","1"+type);
Toast("本聊天解密已开启");
}
}
public String encryptKaiser(String orignal, String str,int type) {
//Toast(str);
long key = Long.parseLong(str);
// 将字符串转为字符数组
char[] chars = orignal.toCharArray();
StringBuilder sb = new StringBuilder();
// 遍历数组
for (char aChar : chars) {
// 获取字符的ASCII编码
long asciiCode = aChar;
// 偏移数据
if(type==1) asciiCode += key;
if(type==0) asciiCode -= key;
// 将偏移后的数据转为字符
char result = (char) asciiCode;
// 拼接数据
sb.append(result);
}
return sb.toString();
}
String getMsg(String msg,String num,int type)//在点击发送按钮发送消息时调用,传递发送消息的内容,返回文本则会修改为文本的内容, 参数1将要发送的消息,参数2为好友号码或群号,参数3为类型,1为群组,2为好友或私聊
{
int type2=type;
if(type==3) type2=2;
if(("1"+type2).equals(getString(num,"加密")))
{
String text;
if(msg.startsWith("[已加密]\n"))
{
text=encryptKaiser(msg.substring(6),MyUin.substring(0,2),0);
//Toast(text);
if(text.startsWith("[已解密]")) return "[已解密]\n"+text.substring(6);
}
else if(msg.startsWith("[已解密]")) text="[已加密]\n"+encryptKaiser(msg,MyUin.substring(0,2),1);
else text="[已加密]\n"+encryptKaiser("[已解密]\n"+msg,MyUin.substring(0,2),1);
return text;
}
else return null;
}
public void onMsg(Object data)
{
String quntext=data.MessageContent;
String qq=data.UserUin;
String qun=data.GroupUin;
String name=data.SenderNickName;
int type=data.MessageType;
if(type==1&&!quntext.contains("[PicUrl="))
{
if(data.IsGroup&&("11".equals(getString(qun,"解密")))||!data.IsGroup&&("12".equals(getString(qq,"解密")))){
//Toast(quntext);
if(quntext.startsWith("[已加密]\n"))
{
String text=encryptKaiser(quntext.substring(6),qq.substring(0,2),0);
//Toast(text);
if(text.startsWith("[已解密]\n"))
{
if(!data.IsSend) data.msg.msg= quntext+"\n--------\n[已解密]\n"+text.substring(6);
else sendTip(data,text);
}
}
}
}
} |
|