Added Ceasar cypher encryption/decryption to BetterChat module - #6554
Added Ceasar cypher encryption/decryption to BetterChat module#6554Adog64 wants to merge 3 commits into
Conversation
|
This is my first PR here, and I'm wondering what you mean by testing code in a production environment. Is that building a jar and using a mod loader or is there some CI/CD task runner that is used or something else? Thank you in advance! Also, is there any additional housekeeping work that I should do (create and link an issue, write unit tests, etc.)? |
testing in a production environment just involves using an actual minecraft launcher rather than fabric loom's |
| .build() | ||
| ); | ||
|
|
||
| private final Setting<Integer> cypherOffset = sgFilter.add(new IntSetting.Builder() |
There was a problem hiding this comment.
| private final Setting<Integer> cypherOffset = sgFilter.add(new IntSetting.Builder() | |
| private final Setting<Integer> cypherOffset = sgGeneral.add(new IntSetting.Builder() |
| StringBuilder modString = new StringBuilder(); | ||
| int msgStart = message.indexOf("> ") + 2; |
There was a problem hiding this comment.
| StringBuilder modString = new StringBuilder(); | |
| int msgStart = message.indexOf("> ") + 2; | |
| int msgStart = message.indexOf("> ") + 2; | |
| StringBuilder modString = new StringBuilder(msgLen - (msgStart + 2)); |
needs double check, i mathed in my head
| // Always decrypt messages regardless of whether we are encrypting them | ||
| String decryptedMessage = applyDecryption(message.getString()); | ||
| message = Component.empty().append(decryptedMessage); |
There was a problem hiding this comment.
i'm not sure whether always decrypting is the behaviour we want, but regardless the message should only be replaced if the text actually contained a caesar cipher encoded message so that:
- we dont allocate a redundant
Component - we dont override the styling information held in
messageunless we actually replace the text it contains
| private String applyDecryption(String message) { | ||
| int msgLen = message.length(); | ||
| StringBuilder modString = new StringBuilder(); | ||
| int msgStart = message.indexOf("> ") + 2; |
There was a problem hiding this comment.
this code incorrectly assumes all incoming chat messages will be decodable, which isn't true (ex. system messages)
specifically, message.indexOf("> ") may return -1 and cause the second character of the message to be read as the cipher's offset which will result in gibberish
additionally, this function should never cause an exception to be thrown otherwise players would be able to remotely crash our users, so please double check everything
Co-authored-by: Crosby <32882447+crosby-moe@users.noreply.github.com>
Co-authored-by: Crosby <32882447+crosby-moe@users.noreply.github.com>
Type of change
Description
Added a simple Ceasar cipher to encrypt and decrypt chat messages. The feature has been added to the BetterChat module. Along with the toggle to enable/disable encryption, there is also an option to set the encryption offset (see Ceasar Cipher on Wikipedia). To avoid weird unicode issues, the cipher only operates on the ASCII characters in the range [32, 126], which includes basically all the characters on an American QWERTY keyboard.
Motivation
With the recent crackdowns on chat regulation on Minecraft servers from Microsoft, certain servers have implemented a chat filter. Chat filters are stupid (both in terms of player freedom and algorithmic complexity). Therefore even a simple cipher like a Ceasar cipher can get around them. I have no doubt that this is a permanent solution, but if this gets patched, I have a few more tricks up my sleeve.
How Has This Been Tested?
Currently, I'm just running
./gradlew runClientand opening a world to LAN for my vanilla client to join. Messages in chat are rendered correctly on the modded instance and show up as garbage in the vanilla instance. Importantly, echoing the same garbage on the vanilla instance, gets decoded on the modded side to produce the original message.So far I've tested with all the typable characters on my keyboard and checked that unicode characters are unaffected. I've also done testing at different offset amounts (min, max, and in between).
Checklist: