diff --git a/src/main/java/net/knarcraft/bookswithoutborders/encryption/EncryptionStyle.java b/src/main/java/net/knarcraft/bookswithoutborders/encryption/EncryptionStyle.java index c63b5bb..a72b468 100644 --- a/src/main/java/net/knarcraft/bookswithoutborders/encryption/EncryptionStyle.java +++ b/src/main/java/net/knarcraft/bookswithoutborders/encryption/EncryptionStyle.java @@ -15,7 +15,7 @@ public enum EncryptionStyle { /** * A simple cipher using the key to substitute one character for another */ - SUBSTITUTION("substitution", true), + SUBSTITUTION("substitution", false), /** * A military-grade encryption cypher @@ -25,7 +25,7 @@ public enum EncryptionStyle { /** * An unbreakable encryption method assuming the key is completely random and never used more than once, ever */ - ONE_TIME_PAD("onetimepad", true), + ONE_TIME_PAD("onetimepad", false), /** * Just a way of using magic text to make text illegible diff --git a/src/main/java/net/knarcraft/bookswithoutborders/encryption/OneTimePad.java b/src/main/java/net/knarcraft/bookswithoutborders/encryption/OneTimePad.java index f73bd8b..ad7a362 100644 --- a/src/main/java/net/knarcraft/bookswithoutborders/encryption/OneTimePad.java +++ b/src/main/java/net/knarcraft/bookswithoutborders/encryption/OneTimePad.java @@ -1,6 +1,5 @@ package net.knarcraft.bookswithoutborders.encryption; -import net.knarcraft.bookswithoutborders.utility.EncryptionHelper; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -27,12 +26,12 @@ public class OneTimePad implements Encryptor { @Override public @Nullable String encryptText(@NotNull String input) { - return oneTimePad(input, true); + return oneTimePad(input); } @Override public @Nullable String decryptText(@NotNull String input) { - return oneTimePad(input, false); + return oneTimePad(input); } /** @@ -41,16 +40,11 @@ public class OneTimePad implements Encryptor { *

The one time pad encryption is very secure, and encryption works just like decryption, but is vulnerable if * the same key is used more than once.

* - * @param input

The input to encrypt/decrypt

- * @param encrypt

Whether to encrypt or decrypt the input

+ * @param input

The input to encrypt/decrypt

* @return

The encrypted/decrypted output

*/ @NotNull - public String oneTimePad(@NotNull String input, boolean encrypt) { - if (!encrypt) { - input = new String(EncryptionHelper.hexStringToByteArray(input), StandardCharsets.UTF_8); - } - + public String oneTimePad(@NotNull String input) { String longKey; try { final MessageDigest digest = MessageDigest.getInstance("SHA3-256"); @@ -64,12 +58,7 @@ public class OneTimePad implements Encryptor { for (int i = 0; i < input.length(); i++) { output.append((char) (input.charAt(i) ^ longKey.charAt(i % longKey.length()))); } - - if (encrypt) { - return EncryptionHelper.bytesToHex(output.toString().getBytes(StandardCharsets.UTF_8)); - } else { - return output.toString(); - } + return output.toString(); } } diff --git a/src/main/java/net/knarcraft/bookswithoutborders/encryption/SubstitutionCipher.java b/src/main/java/net/knarcraft/bookswithoutborders/encryption/SubstitutionCipher.java index 68e7b62..965148d 100644 --- a/src/main/java/net/knarcraft/bookswithoutborders/encryption/SubstitutionCipher.java +++ b/src/main/java/net/knarcraft/bookswithoutborders/encryption/SubstitutionCipher.java @@ -1,11 +1,9 @@ package net.knarcraft.bookswithoutborders.encryption; -import net.knarcraft.bookswithoutborders.utility.EncryptionHelper; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.math.BigInteger; -import java.nio.charset.StandardCharsets; import java.util.StringTokenizer; /** @@ -51,10 +49,6 @@ public class SubstitutionCipher implements Encryptor { return output.toString(); } - if (!encrypt) { - input = new String(EncryptionHelper.hexStringToByteArray(input), StandardCharsets.UTF_8); - } - // converts each number in the key to an integer and adds to an array int[] offsetArray = getOffsetArray(this.key); @@ -75,11 +69,7 @@ public class SubstitutionCipher implements Encryptor { } } - if (encrypt) { - return EncryptionHelper.bytesToHex(output.toString().getBytes(StandardCharsets.UTF_8)); - } else { - return output.toString(); - } + return output.toString(); } /** diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 4e0ed4d..5eeb612 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -34,6 +34,8 @@ Options: # Whether to enable hitting a chiseled bookshelf while sneaking to see the shelf's contents. Enable_Book_Peeking: true # Whether to use true AES encryption when encrypting and decrypting books. While the hashed password used for - # encryption is still stored in the book file, the real contents of the book are not. Admin decrypt can be used to - # peek at books, if an admin gets a hold of one, but only the encrypted AES cypher text is stored in the book. + # encryption is still stored in the book file, the readable contents of the book are not. Admin decrypt can be used to + # peek at books, if an admin gets a hold of a book with the same title and author, but only the encrypted AES cypher text is stored in the book. + # Note that real encryption might alter, corrupt or lose a book's contents, so don't use real encryption with books + # that have no backup in in-game book form or saved book form. Use_Real_Encryption: false \ No newline at end of file