diff --git a/src/main/java/net/knarcraft/bookswithoutborders/utility/EncryptionHelper.java b/src/main/java/net/knarcraft/bookswithoutborders/utility/EncryptionHelper.java index e97a11d..c38d12f 100644 --- a/src/main/java/net/knarcraft/bookswithoutborders/utility/EncryptionHelper.java +++ b/src/main/java/net/knarcraft/bookswithoutborders/utility/EncryptionHelper.java @@ -1,5 +1,15 @@ package net.knarcraft.bookswithoutborders.utility; +import net.knarcraft.bookswithoutborders.BooksWithoutBorders; +import net.knarcraft.bookswithoutborders.EncryptionStyle; +import net.knarcraft.bookswithoutborders.GenenCrypt; +import net.knarcraft.bookswithoutborders.SubstitutionCipher; +import org.bukkit.entity.Player; +import org.bukkit.inventory.meta.BookMeta; + +import java.util.ArrayList; +import java.util.List; + public class EncryptionHelper { /** @@ -15,4 +25,35 @@ public class EncryptionHelper { return integerKey.toString(); } + /** + * Encrypts the pages of a book + * @param book

The book to encrypt

+ * @param style

The encryption style to use

+ * @param integerKey

The encryption key to use

+ * @param player

The player trying to encrypt a book

+ * @return

The pages of the book in encrypted form

+ */ + public static List encryptBookPages(BookMeta book, EncryptionStyle style, String integerKey, Player player) { + List encryptedPages = new ArrayList<>(); + //Scramble the book's contents + if (style == EncryptionStyle.DNA) { + //Encrypt the pages using gene-based encryption + GenenCrypt gc = new GenenCrypt(integerKey); + for (int x = 0; x < book.getPages().size(); x++) { + encryptedPages.add(gc.encrypt(book.getPage(x + 1))); + } + return encryptedPages; + } else if (style == EncryptionStyle.SUBSTITUTION) { + //Encrypt the pages using a substitution cipher + SubstitutionCipher sc = new SubstitutionCipher(); + for (int x = 0; x < book.getPages().size(); x++) { + encryptedPages.add(sc.encrypt(book.getPage(x + 1), integerKey)); + } + return encryptedPages; + } else { + BooksWithoutBorders.sendErrorMessage(player, "Invalid encryption style encountered!"); + return null; + } + } + }