Java library for Ceasar Cipher (Keyed Caesar) that can:
- Encrypt & decrypt english text using keyword and keyword offset (shift)
- Hack encrypted english text using frequency of letters and dictionary of words
- Java JDK 1.8 or later
<dependency>
<groupId>com.github.maximan3000</groupId>
<artifactId>caesar-cipher</artifactId>
<version>1.0.0</version>
</dependency>
implementation 'com.github.maximan3000:caesar-cipher:1.0.0'
Create an encryption system instance
import com.grayen.encryption.caesar.algorithm.Caesar;
import com.grayen.encryption.caesar.algorithm.implementation.CaesarFabric;
Caesar encryption = CaesarFabric.getEncryptionSystem();
Encrypt text using your keywords and offset or it's default values
String textToEncrypt = "Text need to encrypt";
String encryptedText = encryption.encrypt(textToEncrypt, "keyword", 5);
Decrypt with the same way
String textToDecrypt = "Xcyx pccb xq cpauwsx";
String decryptedText = encryption.decrypt(textToDecrypt, "keyword", 5);
Hack system uses dictioanry with english words to improve hacking quality. So you need to create string array with many words. To do that, download large book with .txt extention and parse it to string[].
import java.nio.file.FileSystems;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.nio.file.Files;
Path sourceFile = FileSystems.getDefault().getPath("BigBook.txt");
List<String> fileLines = Files.readAllLines(sourceFile, StandardCharsets.UTF_8);
String[] dictionary = fileLines.toArray(new String[0]);
Create hack system instance.
- Note 1: successful hack depends on encrypted text size
- Note 2: text for dictionary should be large
import com.grayen.encryption.caesar.hack.Hack;
import com.grayen.encryption.caesar.hack.implementation.HackFactory;
Hack hack = HackFactory.getCaesarEncryptionHack(encryptedText, dictionary);
Hack encrypted text
String hackedText = hack.hack();
If it's need, correct hacked text with hands and hack the text again
hack.correctEncryptionTableWithHand("a", "x");
String hackedText = hack.hack();