Skip to content

Bonus-Hunters/security-tasks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

34 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Security Tasks - Encryption & Decryption Algorithms

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.

πŸ” Implemented Algorithms

This repository includes implementations of the following cryptographic algorithms:

Classical Ciphers

  1. Caesar Cipher - A simple substitution cipher that shifts letters by a fixed number of positions
  2. Monoalphabetic Cipher - A substitution cipher with a fixed substitution for each letter
  3. Playfair Cipher - A digraph substitution cipher using a 5Γ—5 key square
  4. Hill Cipher - A polyalphabetic cipher using matrix multiplication
  5. Railfence Cipher - A transposition cipher that arranges plaintext in a rail-like pattern
  6. Columnar Cipher - A transposition cipher that rearranges plaintext based on column permutations

Advanced Ciphers

  1. AutoKey Cipher - An extension of the Vigenère cipher that uses the plaintext as part of the key
  2. Repeating Key Cipher - A polyalphabetic cipher using a repeating key (Vigenère)

Modern Encryption Algorithms

  1. AES (Advanced Encryption Standard) - A symmetric block cipher using 128, 192, or 256-bit keys
  2. DES (Data Encryption Standard) - A symmetric block cipher using 56-bit keys
  3. ElGamal - A public-key cryptosystem based on the discrete logarithm problem
  4. Diffie-Hellman Key Exchange - A method for securely establishing shared keys over an insecure channel

πŸ“ Project Structure

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

πŸš€ Getting Started

Prerequisites

  • Java Development Kit (JDK) 17 or higher
  • Maven 3.6.0 or higher
  • Git (optional, for cloning the repository)

Installation

  1. Clone the repository:

    git clone https://github.com/Bonus-Hunters/security-tasks.git
    cd security-tasks
  2. Build the project:

    mvn clean compile

πŸ—οΈ Building and Running

Compile the project:

mvn clean compile

Run tests:

mvn test

Run a specific test class:

mvn test -Dtest=CaeserCipherTest

Generate project documentation:

mvn javadoc:javadoc

πŸ’» Usage Examples

Each algorithm class provides encrypt() and decrypt() methods with specific parameters:

Caesar Cipher

CaeserCipher cipher = new CaeserCipher();
String encrypted = cipher.encrypt("HELLO", 3);
String decrypted = cipher.decrypt(encrypted, 3);

Playfair Cipher

PlayfairCipher cipher = new PlayfairCipher();
String encrypted = cipher.encrypt("HELLO", "SECRET");
String decrypted = cipher.decrypt(encrypted, "SECRET");

AES Encryption

AES aes = new AES();
String encrypted = aes.encrypt("Hello, World!", "MySecretKey123456");
String decrypted = aes.decrypt(encrypted, "MySecretKey123456");

DES Encryption

DES des = new DES();
String encrypted = des.encrypt("Hello!!!!", "MySecret");
String decrypted = des.decrypt(encrypted, "MySecret");

Diffie-Hellman Key Exchange

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 Encryption

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.

πŸ§ͺ Testing

The project includes comprehensive unit tests for all implemented algorithms using JUnit 5. To run all tests:

mvn test

Tests are located in src/test/java/ and cover:

  • Encryption and decryption correctness
  • Edge cases and special inputs
  • Algorithm-specific requirements

πŸ“ Notes

  • 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

πŸ“„ License

This project is provided for educational purposes as part of the Computer and Network Security course at Ain Shams University.

About

A comprehensive Java implementation of classical and modern encryption/decryption algorithms.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages