A comprehensive Java implementation of classical and modern encryption/decryption algorithms developed for the Computer and Network Security course at the Faculty of Computer and Information Sciences, Ain Shams University.
This repository includes implementations of the following cryptographic algorithms:
- Caesar Cipher - A simple substitution cipher that shifts letters by a fixed number of positions
- Monoalphabetic Cipher - A substitution cipher with a fixed substitution for each letter
- Playfair Cipher - A digraph substitution cipher using a 5Γ5 key square
- Hill Cipher - A polyalphabetic cipher using matrix multiplication
- Railfence Cipher - A transposition cipher that arranges plaintext in a rail-like pattern
- Columnar Cipher - A transposition cipher that rearranges plaintext based on column permutations
- AutoKey Cipher - An extension of the Vigenère cipher that uses the plaintext as part of the key
- Repeating Key Cipher - A polyalphabetic cipher using a repeating key (Vigenère)
- AES (Advanced Encryption Standard) - A symmetric block cipher using 128, 192, or 256-bit keys
- DES (Data Encryption Standard) - A symmetric block cipher using 56-bit keys
- ElGamal - A public-key cryptosystem based on the discrete logarithm problem
- Diffie-Hellman Key Exchange - A method for securely establishing shared keys over an insecure channel
security-tasks/
βββ pom.xml # Maven configuration file
βββ README.md # This file
βββ src/
βββ main/java/
β βββ org/example/
β β βββ Main.java # Main entry point
β βββ Security/ # All algorithm implementations
β βββ AES.java
β βββ AutoKey.java
β βββ CaeserCipher.java
β βββ ColumnarCipher.java
β βββ DES.java
β βββ DiffieHellman.java
β βββ ElGamal.java
β βββ HillCipher.java
β βββ MonoalphabeticCipher.java
β βββ PlayfairCipher.java
β βββ Railfence.java
β βββ RepeatingKey.java
βββ test/java/ # Unit tests for each algorithm
βββ AESTest.java
βββ AutoKeyTest.java
βββ CaeserCipherTest.java
βββ ColumnarCipherTest.java
βββ DESTest.java
βββ DiffieHellmanTest.java
βββ ElgamalTest.java
βββ HillCipherTest.java
βββ MonoalphabeticCipherTest.java
βββ PlayfairCipherTest.java
βββ RailfenceTest.java
βββ RepeatingKeyTest.java
- Java Development Kit (JDK) 17 or higher
- Maven 3.6.0 or higher
- Git (optional, for cloning the repository)
-
Clone the repository:
git clone https://github.com/Bonus-Hunters/security-tasks.git cd security-tasks -
Build the project:
mvn clean compile
mvn clean compilemvn testmvn test -Dtest=CaeserCipherTestmvn javadoc:javadocEach algorithm class provides encrypt() and decrypt() methods with specific parameters:
CaeserCipher cipher = new CaeserCipher();
String encrypted = cipher.encrypt("HELLO", 3);
String decrypted = cipher.decrypt(encrypted, 3);PlayfairCipher cipher = new PlayfairCipher();
String encrypted = cipher.encrypt("HELLO", "SECRET");
String decrypted = cipher.decrypt(encrypted, "SECRET");AES aes = new AES();
String encrypted = aes.encrypt("Hello, World!", "MySecretKey123456");
String decrypted = aes.decrypt(encrypted, "MySecretKey123456");DES des = new DES();
String encrypted = des.encrypt("Hello!!!!", "MySecret");
String decrypted = des.decrypt(encrypted, "MySecret");DiffieHellman dh = new DiffieHellman();
// Alice and Bob establish a shared secret key
long aliceShared = dh.calculateSharedSecret(alicePrivate, bobPublic, p);
long bobShared = dh.calculateSharedSecret(bobPrivate, alicePublic, p);ElGamal elGamal = new ElGamal();
long[] encrypted = elGamal.encrypt(message, p, g, publicKey);
long decrypted = elGamal.decrypt(encrypted, p, privateKey);Some algorithms provide an Analyze method to find the secret key used for encryption.
The project includes comprehensive unit tests for all implemented algorithms using JUnit 5. To run all tests:
mvn testTests are located in src/test/java/ and cover:
- Encryption and decryption correctness
- Edge cases and special inputs
- Algorithm-specific requirements
- Classical ciphers (Caesar, Playfair, Hill, etc.) typically work with uppercase alphabetic characters
- Modern encryption algorithms (AES, DES) support various character sets and typically use Base64 encoding for output
- Some algorithms may have specific key requirements (length, format, etc.) - refer to individual class documentation
- All implementations are for educational purposes and should not be used for production security
This project is provided for educational purposes as part of the Computer and Network Security course at Ain Shams University.