From 76dd2b4cd089cd30ddb0305a004c28ebc7fb9e71 Mon Sep 17 00:00:00 2001 From: TudbuT Date: Sun, 26 May 2024 02:17:34 +0200 Subject: [PATCH] make CC:keep better --- .../client/module/chat/ChatCrypt.java | 35 +++++++++++++++---- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/Client/src/main/java/com/baseband/client/module/chat/ChatCrypt.java b/Client/src/main/java/com/baseband/client/module/chat/ChatCrypt.java index 5f7f405..12d42ce 100644 --- a/Client/src/main/java/com/baseband/client/module/chat/ChatCrypt.java +++ b/Client/src/main/java/com/baseband/client/module/chat/ChatCrypt.java @@ -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]; {