A from-scratch Java implementation of classical and modern ciphers, with cryptanalysis routines that recover keys from known plaintext/ciphertext pairs.
This repository implements a range of encryption algorithms in plain Java, with
no cryptography libraries. Each cipher provides encrypt and decrypt, and most
classical ciphers also provide an analyse method that performs a known-plaintext
attack — given a plaintext and its corresponding ciphertext, it recovers the key.
AES-128 and DES are included as full block-cipher implementations operating on
hexadecimal input. It started as an information-security course project and is
intended for study rather than production use.
- Ten ciphers implemented by hand (no crypto libraries).
- Encrypt and decrypt for every cipher.
- Cryptanalysis (
analyse) for the classical ciphers — recovers the key from a known plaintext/ciphertext pair. - Frequency-based analysis for the monoalphabetic cipher
(
analyseUsingCharFrequency). - A JUnit 5 test suite (45 tests) covering every cipher.
| Cipher | Encrypt | Decrypt | Cryptanalysis |
|---|---|---|---|
| Caesar | ✓ | ✓ | ✓ |
| Monoalphabetic | ✓ | ✓ | ✓ (known-plaintext + frequency) |
| Autokey | ✓ | ✓ | ✓ |
| Repeating-key (Vigenère) | ✓ | ✓ | ✓ |
| Playfair | ✓ | ✓ | — |
| Hill (2×2 & 3×3) | ✓ | ✓ | ✓ (3×3 key recovery) |
| Rail fence | ✓ | ✓ | ✓ |
| Columnar transposition | ✓ | ✓ | ✓ |
| AES-128 | ✓ | ✓ | — |
| DES | ✓ | ✓ | — |
- Java 17
- Maven
- JUnit 5 (Jupiter)
- JDK 17 or newer
- Maven
git clone https://github.com/Omar-Elhakim/Encryption-Techniques.git
cd Encryption-Techniques
mvn testThe ciphers live in src/main/java/Security/; the JUnit tests in
src/test/java/ double as usage examples.
The ciphers are used as plain Java classes. Example with the Caesar cipher:
import Security.CaeserCipher;
CaeserCipher caesar = new CaeserCipher();
String cipher = caesar.encrypt("meetmeaftertheparty", 3); // "phhwphdiwhuwkhsduwb"
String plain = caesar.decrypt(cipher, 3); // "meetmeaftertheparty"
int key = caesar.analyse("meetmeaftertheparty", cipher); // 3AES-128 and DES operate on hexadecimal strings:
import Security.AES;
AES aes = new AES();
String cipher = aes.encrypt("0x00112233445566778899aabbccddeeff",
"0x000102030405060708090a0b0c0d0e0f");
String plain = aes.decrypt(cipher,
"0x000102030405060708090a0b0c0d0e0f");src/
main/java/Security/ # cipher implementations
test/java/ # JUnit tests (also serve as examples)
pom.xml # Maven build + JUnit 5 dependency
Released under the MIT License.