Skip to content

Latest commit

 

History

History
281 lines (219 loc) · 10.4 KB

File metadata and controls

281 lines (219 loc) · 10.4 KB

Encryption, Decryption, Encoding & Decoding Java Suite

A comprehensive Java implementation of classic cryptography algorithms, encoding/decoding schemes, and hashing mechanisms built from scratch using core Java logic without relying on external security libraries.


Table of Contents


Overview

This repository contains clean, core Java programs designed to demonstrate fundamental cryptographic operations and data representation transformations. Each module is self-contained with standard interactive console inputs (java.util.Scanner), making it ideal for educational purposes, security foundational studies, and algorithm analysis.


Project Architecture & Directory Structure

Encryption-Decryption-Encoding-Decoding/
├── Encryption/                # Symmetric and substitution cipher algorithms
│   ├── Ceaser_Cipher.java     # Caesar Cipher encryption
│   ├── ROT13.java             # ROT13 substitution encryption
│   ├── Vigenere_cipher.java   # Vigenère polyalphabetic cipher encryption
│   └── XOR.java               # Bitwise XOR cipher encryption
├── Decryption/                # Reverse operations for cryptographic algorithms
│   ├── Ceaser_cipher.java     # Caesar Cipher decryption
│   ├── ROT13.java             # ROT13 decryption
│   ├── Vigenere_cipher.java   # Vigenère cipher decryption
│   └── XOR.java               # Bitwise XOR cipher decryption
├── Encode/                    # Binary and text encoding schemes
│   ├── Base_64.java           # Custom 6-bit chunking Base64 encoder
│   ├── binary.java            # ASCII character to 8-bit binary string encoder
│   ├── MorseCode.java         # Alphanumeric text to Morse Code (. / -) encoder
│   ├── Unix_to_Unix.java      # UUEncoding (Unix-to-Unix binary-to-text) encoder
│   └── URL.java               # Percent-encoding for special URL characters
├── Decode/                    # Reverse transformations for encoding schemes
│   ├── Base64.java            # Base64 decoder back to plain text
│   ├── Binary.java            # 8-bit binary string to plain ASCII decoder
│   ├── MorseCode.java         # Morse Code (. / -) to ASCII text decoder
│   ├── Unix-to-Unix.java      # UUDecoding back to ASCII text
│   └── URL.java               # URL percent-decoding back to plain text
├── Hashing/                   # One-way cryptographic hash functions
│   └── SHA_256.java           # Custom SHA-256 block infrastructure & 512-bit message padding
├── LICENSE                    # MIT License
└── README.md                  # Detailed documentation

Supported Algorithms & Implementation Details

1. Encryption & Decryption (/Encryption & /Decryption)

  • Caesar Cipher (Ceaser_Cipher.java / Ceaser_cipher.java)

    • Mechanism: Shifts alphabetic characters by a user-defined integer key modulo 26 ((c - 'a' + key) % 26).
    • Preservation: Preserves case (uppercase and lowercase letters are handled separately); non-alphabetic characters remain unchanged.
  • ROT13 (ROT13.java)

    • Mechanism: A fixed special case of the Caesar cipher using a fixed key shift of 13 positions ((c - 'a' + 13) % 26).
    • Symmetric nature: Shifting twice by 13 results in the original text (26-letter alphabet).
  • Vigenère Cipher (Vigenere_cipher.java)

    • Mechanism: Polyalphabetic substitution cipher using a repeated keyword.
    • Key Expansion: Automatically extends/repeats the key string to match the length of the plaintext string before applying modular shifts.
  • XOR Cipher (XOR.java)

    • Mechanism: Bitwise XOR (^) operation between character ASCII binary representations and key binary representations expanded across 8-bit byte frames.

2. Encoding & Decoding (/Encode & /Decode)

  • Base64 (Base_64.java / Base64.java)

    • Mechanism: Converts text into 8-bit binary chunks, concatenates them into a unified bit stream, groups them into 6-bit blocks, and maps each 6-bit index to the Base64 index table (A-Z, a-z, 0-9, +, /). Appends 0 padding bits where required.
  • Binary Encoding (binary.java / Binary.java)

    • Mechanism: Converts each ASCII character of the input string into a padded 8-bit binary representation (e.g., 'A' $\rightarrow$ 01000001).
  • Morse Code (MorseCode.java)

    • Mechanism: Maps letters (A–Z), numbers (0–9), and special punctuation (., ,, ?, !, /, etc.) to standard International Morse Code signals composed of dots (.) and dashes (-).
  • UUEncoding (Unix_to_Unix.java / Unix-to-Unix.java)

    • Mechanism: Historical Unix-to-Unix encoding scheme that converts binary/text streams into 6-bit printable ASCII characters (offset by ASCII code 32), adding length byte headers and grave accent (`) padding.
  • URL Percent Encoding (URL.java)

    • Mechanism: Replaces reserved or non-alphanumeric characters (such as space , !, #, $, &, =) with their corresponding %HEX ASCII representations (e.g., space becomes %20).

3. Hashing (/Hashing)

  • SHA-256 (SHA_256.java)
    • Mechanism: Custom low-level implementation of SHA-256 block creation and message preprocessing:
      1. Converts UTF-8 input string to binary bits.
      2. Applies 512-bit block calculation.
      3. Performs primary padding (1 bit appended as 0s), intermediate zero-padding, and 64-bit Big-Endian length attachment.
      4. Constructs block infrastructure (blockInfraStructure) mapping 32-bit unsigned words ($W_0 \dots W_{15}$).

Prerequisites

  • Java Development Kit (JDK): JDK 8 or higher (JDK 11 / JDK 17 / JDK 21 recommended).
  • Terminal / Command Prompt / Shell access.

Verify your local Java installation:

java -version
javac -version

Compilation & Execution Guide

Navigate to the project root directory before executing compilation commands:

cd /Users/pasu/Desktop/Encryption

Encryption Examples

Caesar Cipher

# Compile
javac Encryption/Ceaser_Cipher.java

# Run Encryption
java -cp Encryption Ceaser_cipher

Sample Prompt:

Plaintext: Hello World
Key: 3

Plaintext: Hello World
Ciphertext: Khoor Zruog
--------------------------

ROT13

javac Encryption/ROT13.java
java -cp Encryption ROT13

Vigenère Cipher

javac Encryption/Vigenere_cipher.java
java -cp Encryption Vigenere_cipher

Decryption Examples

Caesar Cipher Decryption

javac Decryption/Ceaser_cipher.java
java -cp Decryption Ceaser_cipher

Sample Prompt:

ciphertext: Khoor Zruog
Key: 3

Ciphertext: Khoor Zruog
Plaintext: Hello World
--------------------------

Vigenère Cipher Decryption

javac Decryption/Vigenere_cipher.java
java -cp Decryption Vigenere_cipher

Encoding Examples

Base64 Encoding

javac Encode/Base_64.java
java -cp Encode base64_encode

Binary Encoding

javac Encode/binary.java
java -cp Encode binary

Morse Code Encoding

javac Encode/MorseCode.java
java -cp Encode MorseCode_encode

Decoding Examples

Base64 Decoding

javac Decode/Base64.java
java -cp Decode base64_decode

Binary Decoding

javac Decode/Binary.java
java -cp Decode Binary_decode

Morse Code Decoding

javac Decode/MorseCode.java
java -cp Decode MorseCode_Decode

Hashing Examples

SHA-256 Preprocessing & Block Structure

javac Hashing/SHA_256.java
java -cp Hashing SHA_Hash

Sample Output:

Input: Hello World
Combined Length of Total Blocks: 512
Total blocks used: 1

Detailed Walkthrough of Modules

Category File Main Class Core Technique
Encryption Ceaser_Cipher.java Ceaser_cipher Alphabet Modular Shift
Encryption ROT13.java ROT13 13-Position Shift
Encryption Vigenere_cipher.java Vigenere_cipher Keyword Polyalphabetic Shift
Encryption XOR.java XOR Bitwise XOR (^) on 8-bit ASCII
Decryption Ceaser_cipher.java Ceaser_cipher Reverse Modular Shift
Decryption ROT13.java ROT13 13-Position Reverse Shift
Decryption Vigenere_cipher.java Vigenere_cipher Key-based Reverse Substitution
Decryption XOR.java XOR Symmetric Bitwise XOR
Encode Base_64.java base64_encode 8-bit to 6-bit Base64 Table Mapping
Encode binary.java binary ASCII Byte to 8-bit Binary String
Encode MorseCode.java MorseCode_encode Lookup Map to Dots and Dashes
Encode Unix_to_Unix.java UUEncoding Unix Binary-to-ASCII Encoding
Encode URL.java URL_encoding Reserved Char to Percent-Encoding
Decode Base64.java base64_decode Base64 Index to 8-bit Byte Reconstruction
Decode Binary.java Binary_decode 8-bit Binary Chunk to ASCII Char
Decode MorseCode.java MorseCode_Decode Dot/Dash Tokens to ASCII
Decode Unix-to-Unix.java UUDecoding Unix UUDecode Stream to ASCII
Decode URL.java URL_decoding Percent-Hex Tokens to ASCII
Hashing SHA_256.java SHA_Hash SHA-256 Preprocessing, Padding & Block Split

License

This repository is licensed under the MIT License. Feel free to use, modify, and distribute for learning and development.