Skip to content

VN4x/Java_Cypher_Tool

Repository files navigation

Java Cypher Tool

A simple, interactive command-line tool for encrypting and decrypting messages using classic algorithms. Designed for encryption enthusiasts and Java students.

Features

  • Encrypt & Decrypt: Choose between two modes.
  • Algorithms:
    • ROT13: A classic shift cipher (shift by 13).
    • Atbash: Reverses the alphabet (A -> Z, B -> Y).
    • Caesar Cipher: A historical cipher with a fixed shift of 3.
  • Robust Input: handles invalid inputs options and empty strings gracefully.

How to Run

  1. Compile:
    javac Main.java CypherTool.java
  2. Run:
    java Main

Usage Example

Welcome to the Cypher Tool!

Select operation:
1. Encrypt
2. Decrypt
$> 1

Select cypher:
1. ROT13
2. Atbash
3. Caesar (Shift 3)
$> 1

Enter the message:
$> Hello World!

Encrypted message (ROT13):
Uryyb Jbeyq!

Main Method Flow

The main() method controls the entire program:

1. Display welcome message
2. Loop forever:
   a. Ask user: Encrypt, Decrypt, or Exit?
   b. If Exit → quit program
   c. Ask which cipher to use
   d. Ask for message input
   e. Validate input
   f. Process message (encrypt or decrypt)
   g. Display result
   h. Go back to step 2

Key Concept: The loop allows users to process multiple messages without restarting the program.


Two Cipher Algorithms Explained

1. ROT13 (Rotate by 13)

What it does: Shifts each letter 13 positions forward in the alphabet.

Visual Example:

Original:  A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
ROT13:     N O P Q R S T U V W X Y Z A B C D E F G H I J K L M

H e l l o  →  U r y y b
(shift 13)

Why ROT13 is special: Applying ROT13 twice gives you the original message back!

"Hello" → ROT13 → "Uryyb" → ROT13 → "Hello"

Code Logic:

(c - 'A' + 13) % 26
  • c - 'A' = position in alphabet (0-25)
  • + 13 = shift by 13
  • % 26 = wrap around using modulo (when we go past Z, wrap to A)

Example: H (position 7) → (7 + 13) % 26 = 20 → U


Project Structure

  • Main.java: Entry point.
  • CypherTool.java: Contains all logic and encryption algorithms.
  • STUDY_GUIDE.md: Explains the math and logic behind the code.
  • pseudocode.txt: High-level logic overview.
  • presentation.md: preparation for project presentation to tutors.

About

tech group task 1

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages