make CC:keep better

This commit is contained in:
Daniella / Tove 2024-05-26 02:17:34 +02:00
parent d5ee578f57
commit 76dd2b4cd0

View file

@ -128,6 +128,11 @@ public class ChatCrypt extends Feature {
GlobalUtil.LOGGER.info("decrypt: {}", message);
byte[] original = recoverBytes(message);
if(!useSBE && decryptNoKeep(original).equals("CC:keep") && allowCCKeep) {
keepTrypt = true;
trypt = null;
HUD.notifyAndPrint("§c§lChat>§c Enabled and synchronized Trypt keep.");
}
message = decrypt(original);
if(!useSBE && keepTrypt && (!isOurs || !sentOriginal.equals(message))) {
@ -144,12 +149,6 @@ public class ChatCrypt extends Feature {
sentEncrypted = null;
sentOriginal = null;
if(!useSBE && message.equals("CC:keep") && allowCCKeep) {
keepTrypt = true;
trypt = null;
HUD.notifyAndPrint("§c§lChat>§c Enabled and synchronized Trypt keep.");
}
try {
FieldFinder.findUnmarked(SPacketChat.class, ITextComponent.class, 0).set(e.getPacket(), new TextComponentString("§dChatCrypt> §r" + username + ": " + message));
} catch (IllegalAccessException ex) {
@ -179,7 +178,10 @@ public class ChatCrypt extends Feature {
return;
sentOriginal = s;
s = encrypt(s);
if(s.equals("CC:keep") && allowCCKeep)
s = encryptNoKeep(s);
else
s = encrypt(s);
sentEncrypted = s;
s += getTerminator();
if (s.length() > 256) {
@ -217,6 +219,25 @@ public class ChatCrypt extends Feature {
}
}
public String encryptNoKeep(String value) {
if (useSBE) {
SBE sbe = new SBE(Hasher.sha512hex(password).getBytes(StandardCharsets.UTF_8), boxSize, seed);
return armorBytes(sbe.transform(value.getBytes(StandardCharsets.UTF_8)));
} else {
return armorBytes(new Trypt(seed, Hasher.sha512hex(password).getBytes(StandardCharsets.UTF_8)).encryptChunk(value.getBytes(StandardCharsets.UTF_8)));
}
}
public String decryptNoKeep(byte[] encrypted) {
if(useSBE) {
SBE sbe = new SBE(Hasher.sha512hex(password).getBytes(StandardCharsets.UTF_8), boxSize, seed);
return new String(sbe.transform(encrypted), StandardCharsets.US_ASCII);
}
else {
return new String(new Trypt(seed, Hasher.sha512hex(password).getBytes(StandardCharsets.UTF_8)).decryptChunk(encrypted), StandardCharsets.UTF_8);
}
}
final char[] table = "!#$%&'()*+,-0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_abcdefghijklmnopqrstuvwxyz{|}~¡¢£¥¦«²³¹»ÆÇÈÉÊÑÒÓÖÙÚÜßàáäåæçèéêñòóöùü×".toCharArray();
final byte[] rtable = new byte[256];
{