Skip to content

xedi1/NeonCaesarCipher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

6 Commits
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ’ก NeonCaesarCipher ๐Ÿ”

A minimal Java CLI app that encrypts & decrypts text using the classic Caesar cipher with a custom shift.
Simple ยท Educational ยท Neon-Styled ๐Ÿ”ฎ


๐ŸŽฏ Overview

NeonCaesarCipher is a tiny Java console program that:

  • ๐Ÿ” Takes a text input from the user
  • ๐ŸŽš Applies a Caesar cipher with a custom shift k
  • ๐Ÿงฉ Shows both the encrypted and decrypted message

It supports:

  • โœ… Uppercase letters: Aโ€“Z
  • โœ… Lowercase letters: aโ€“z
  • โœ… Keeps nonโ€‘letter characters unchanged (spaces, punctuation, digits, etc.)

๐Ÿ“ฆ Features

Feature Description
๐Ÿ”ค Case-sensitive cipher Uppercase and lowercase handled separately
๐ŸŽš Custom shift (k) You choose how many positions to rotate letters
๐Ÿ” Bidirectional encrypt() and decrypt() implemented
๐Ÿงฎ Wrap-around logic Shifts correctly wrap inside Aโ€“Z / aโ€“z
๐Ÿ’ป CLI-based Runs directly in your terminal / command prompt
๐Ÿ“š Simple, educational example Great for learning about Caesar ciphers & basic Java input/output

๐Ÿง  How It Works (Caesar Cipher)

The Caesar cipher shifts each letter by k positions in the alphabet.

For encryption:

  • For uppercase letters:

    char encryptedCh = (char) (((int) ch - 'A' + Shift) % 26 + 'A');
  • For lowercase letters:

    char encryptedCh = (char) (((int) ch - 'a' + Shift) % 26 + 'a');

For decryption, instead of writing new logic, the code reuses encrypt() with a reverse shift:

public String decrypt(String S, int Shift) {
    return encrypt(S, 26 - (Shift % 26));
}

So, decrypt is just:

[ \text{decrypt}(S, k) = \text{encrypt}(S, 26 - (k \bmod 26)) ]


๐Ÿ—‚ Project Structure

NeonCaesarCipher/
โ”œโ”€ src/
โ”‚  โ””โ”€ main/
โ”‚     โ””โ”€ main.java    # Main class with encrypt/decrypt logic and CLI
โ””โ”€ README.md

โš™๏ธ Requirements

  • โ˜• Java JDK 8+ (11, 17, etc. also fine)
  • ๐Ÿ–ฅ Any OS that can run Java:
    • Windows
    • macOS
    • Linux

๐Ÿš€ Getting Started

1๏ธโƒฃ Clone or Download

git clone https://github.com/xedi1/NeonCaesarCipher.git
cd NeonCaesarCipher

2๏ธโƒฃ Source Code (main.java)

Make sure your file path is:

src/main/main.java

3๏ธโƒฃ Compile

From the project root:

cd src
javac main/main.java

This will create main.class inside src/main/.


4๏ธโƒฃ Run

From inside src:

java main.main

๐Ÿงช Example Usage

โ–ถ Sample Run #1

Input:

======= Encypt Decode System (Edi)========
Enter String:
HelloWorld
Enter K(Count Movement)
3

Output:

Encrypt Message:KhoorZruog
Decrypt Message:HelloWorld

Explanation:

  • H -> K, e -> h, l -> o, etc. shifted by 3 positions.
  • Decrypting with the same k = 3 returns the original text.

โ–ถ Sample Run #2 (with non-letters)

If you modify input handling to support spaces and run:

Input:
S = "Hello, World!", k = 5

Encrypted:
Mjqqt, Btwqi!

  • Letters are shifted.
  • Punctuation and spaces stay the same.

๐Ÿ“š API / Methods

Method Signature Description
String encrypt(String S, int Shift) Encrypts string S by shifting letters by Shift
String decrypt(String S, int Shift) Decrypts string S using inverse shift

๐Ÿ” encrypt(...)

  • Loops over each character
  • Checks:
    • Character.isUpperCase(ch) โ†’ applies uppercase formula
    • Character.isLowerCase(ch) โ†’ applies lowercase formula
    • Else โ†’ appends character as-is

๐Ÿ”“ decrypt(...)

  • Computes the reverse shift:

    26 - (Shift % 26)
  • Calls encrypt() with that reverse shift.


โœจ Possible Improvements (Ideas)

You can keep the code as-is, or upgrade it into a more โ€œneonโ€ project:

  • ๐Ÿงต Support full-line input using nextLine() instead of next()
  • ๐ŸŽš Allow negative shifts
  • ๐Ÿ“ Read/write from files
  • ๐ŸŒˆ Add colored output using ANSI escape codes
  • ๐Ÿ”’ Add option to brute-force all 26 shifts (for cracking Caesar cipher)
  • ๐Ÿงช Add unit tests (e.g., with JUnit)

๐Ÿงฑ Building a Jar (Optional)

From src:

javac main/main.java
jar cfe NeonCaesarCipher.jar main.main main/*.class

Then run:

java -jar NeonCaesarCipher.jar

๐Ÿค Contributing

Contributions are welcome!

  1. ๐Ÿด Fork the repo
  2. ๐ŸŒฟ Create a feature branch
    git checkout -b feature/my-cool-feature
  3. โœ๏ธ Commit your changes
    git commit -m "Add awesome feature"
  4. ๐Ÿ“ค Push the branch
    git push origin feature/my-cool-feature
  5. ๐Ÿ” Open a Pull Request

๐Ÿงพ License

This project is free to use for learning & experimentation.
license (Apache 2.0) by creating a Edi.


๐Ÿ“ฃ Author

  • ๐Ÿ’ป Original code by Edi
  • ๐ŸŒ GitHub: https://github.com/xedi1

๐Ÿ’ฌ Final Notes

NeonCaesarCipher is a neat example of:

  • String manipulation in Java
  • Using Scanner for console input
  • Implementing a classic cryptographic algorithm

Perfect for beginners who want a small but complete Java project in their GitHub.

About

๐Ÿ” A Java CLI app that encrypts and decrypts text using a classic Caesar cipher with a custom shift.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages