A minimal Java CLI app that encrypts & decrypts text using the classic Caesar cipher with a custom shift.
Simple ยท Educational ยท Neon-Styled ๐ฎ
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.)
| 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 |
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)) ]
NeonCaesarCipher/
โโ src/
โ โโ main/
โ โโ main.java # Main class with encrypt/decrypt logic and CLI
โโ README.md
- โ Java JDK 8+ (11, 17, etc. also fine)
- ๐ฅ Any OS that can run Java:
- Windows
- macOS
- Linux
git clone https://github.com/xedi1/NeonCaesarCipher.git
cd NeonCaesarCipherMake sure your file path is:
src/main/main.java
From the project root:
cd src
javac main/main.javaThis will create main.class inside src/main/.
From inside src:
java main.mainInput:
======= 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 by3positions.- Decrypting with the same
k = 3returns the original text.
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.
| 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 |
- Loops over each character
- Checks:
Character.isUpperCase(ch)โ applies uppercase formulaCharacter.isLowerCase(ch)โ applies lowercase formula- Else โ appends character as-is
-
Computes the reverse shift:
26 - (Shift % 26)
-
Calls
encrypt()with that reverse shift.
You can keep the code as-is, or upgrade it into a more โneonโ project:
- ๐งต Support full-line input using
nextLine()instead ofnext() - ๐ 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)
From src:
javac main/main.java
jar cfe NeonCaesarCipher.jar main.main main/*.classThen run:
java -jar NeonCaesarCipher.jarContributions are welcome!
- ๐ด Fork the repo
- ๐ฟ Create a feature branch
git checkout -b feature/my-cool-feature
- โ๏ธ Commit your changes
git commit -m "Add awesome feature" - ๐ค Push the branch
git push origin feature/my-cool-feature
- ๐ Open a Pull Request
This project is free to use for learning & experimentation.
license (Apache 2.0) by creating a Edi.
- ๐ป Original code by Edi
- ๐ GitHub:
https://github.com/xedi1
NeonCaesarCipher is a neat example of:
- String manipulation in Java
- Using
Scannerfor console input - Implementing a classic cryptographic algorithm
Perfect for beginners who want a small but complete Java project in their GitHub.